8.Eclipse中创建Maven Web项目
第一步:
創建maven web工程
注意下面一步:
第二步:
繼承parent
修改pom.xml文件如下
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
?xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
?<modelVersion>4.0.0</modelVersion>
?<groupId>cn.toto.maven</groupId>
?<artifactId>web</artifactId>
?<packaging>war</packaging>
?<name>web Maven Webapp</name>
?<url>http://maven.apache.org</url>
?
? <parent>?
???<groupId>cn.toto.maven</groupId>
??? <artifactId>Parent</artifactId>
? ? <version>0.0.1-RELEASE</version>
???<relativePath>../Parent/pom.xml</relativePath>?
?</parent>
?
?<dependencies>
???<dependency>
?????<groupId>junit</groupId>
????? <artifactId>junit</artifactId>
???</dependency>
???<dependency>
?????<groupId>cn.toto.maven</groupId>
?????<artifactId>MakeFriends</artifactId>
???</dependency>
?</dependencies>
?
</project>
?
第三步:
建立測試jsp
<%@ page language="java"contentType="text/html; charset=UTF-8"
??? pageEncoding="UTF-8"%>
<%@ pageimport="cn.toto.maven.MakeFriends.*"%>
<%
??? MakeFriendsmakeFriends=new MakeFriends();
???out.println(makeFriends.makeFriends("wanglipeng"));
%>
?
第四步:
自動部署到tomcat下面(web項目下的pom.xml中)
<build>
???<finalName>web</finalName>
???<plugins>
?????????<plugin>
?????????????<groupId>org.codehaus.cargo</groupId>
?????????????<artifactId>cargo-maven2-plugin</artifactId>
? ???????? ??<version>1.2.3</version>
? ???????? ??<configuration>
? ???????? ??????<container>
? ???????? ??????????<containerId>tomcat7x</containerId>
?????????????????????<!—下面是Tomcat在電腦上的位置à
? ???????? ??????????<home>D:/Program Files/ApacheSoftware Foundation/Tomcat 5.0</home>
? ???????? ??????</container>
? ???????? ??????<configuration>
? ???????? ??????????<type>existing</type>
? ???????? ??????????<home>D:/Program Files/ApacheSoftware Foundation/Tomcat 5.0</home>
? ???????? ??????</configuration>
? ???????? ??</configuration>
? ???????? ??<executions>?
?????????????????<execution>?
?????????????????????<id>cargo-run</id>?
?????????????????????<phase>install</phase>?
?????????????????????<goals>?
?????????????????????????<goal>run</goal>?
?????????????????????</goals>?
?????????????????</execution>?
?????????????</executions>
?????????</plugin>
?????</plugins>
? </build>
?
第五步:
模塊聚合
修改parent.pom
?
Web模塊中的完整的pox.xml如下:
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ? xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> ? <modelVersion>4.0.0</modelVersion> ? <artifactId>web</artifactId> ? <packaging>war</packaging> ? ? <name>web Maven Webapp</name> ? ?? <parent>? ????? ? <groupId>cn.toto.maven</groupId> ??? ??? <artifactId>Parent</artifactId> ? ? ????<version>0.0.1-SNAPSHOT</version> ??????? <relativePath>../Parent/pom.xml</relativePath>? ? </parent> ? <dependencies> ? <dependency> ????? <groupId>junit</groupId> ????? <artifactId>junit</artifactId> ??? </dependency> ??? <dependency> ????? <groupId>cn.toto.maven</groupId> ????? <artifactId>MakeFriends</artifactId> ??? </dependency> </dependencies> ? <build> ??? <finalName>web</finalName> ??? <plugins> ????????? <plugin> ????????????? <groupId>org.codehaus.cargo</groupId> ????????????? <artifactId>cargo-maven2-plugin</artifactId> ? ???????? ??<version>1.2.3</version> ? ???????? ??<configuration> ? ???????? ??????<container> ? ???????? ??????????<containerId>tomcat7x</containerId> ????????????????????? <!—下面是Tomcat在電腦上的位置à ? ???????? ??????????<home>D:/Program Files/Apache Software Foundation/Tomcat 5.0</home> ? ???????? ??????</container> ? ???????? ??????<configuration> ? ???????? ??????????<type>existing</type> ? ???????? ??????????<home>D:/Program Files/Apache Software Foundation/Tomcat 5.0</home> ? ???????? ??????</configuration> ? ???????? ??</configuration> ? ???????? ??<executions>? ????????????????? <execution>? ? ????????????????????<id>cargo-run</id>? ????????????????????? <phase>install</phase>? ????????????????????? <goals>? ????????????????????????? <goal>run</goal>? ????????????????????? </goals>? ????????????????? </execution>? ????????????? </executions> ????????? </plugin> ????? </plugins> ? </build> ? </project> |
| 注意: |
?
Parent中的pom.xml如下:
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ? xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> ? <modelVersion>4.0.0</modelVersion> ? ? <groupId>cn.toto.maven</groupId> ? <artifactId>Parent</artifactId> ? <version>0.0.1-SNAPSHOT</version> ? <packaging>pom</packaging> ? ? <name>Parent</name> ? <url>http://maven.apache.org</url> <modules> ? ? <module>../Hello</module>? ? ? <module>../HelloFriend</module>??? ? ? <module>../MakeFriends</module> ? ? <module>../web</module> </modules> ? <properties> ??? <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> ? </properties> ? ? <dependencyManagement> ? <dependencies> ??? <dependency> ????? <groupId>junit</groupId> ????? <artifactId>junit</artifactId> ????? <version>4.9</version> ????? <scope>test</scope> ??? </dependency> ??? <dependency> ????? <groupId>cn.toto.maven</groupId> ? ? ??<artifactId>HelloFriend</artifactId> ????? <version>0.0.1-SNAPSHOT</version> ????? <scope>compile</scope> ??? </dependency> ??? <dependency> ?????????? <groupId>cn.toto.maven</groupId> ?????????? <artifactId>Hello</artifactId> ?????????? <version>0.0.1-SNAPSHOT</version> ?????????? <scope>compile</scope> ?????? </dependency> ?????? <dependency> ?????????? <groupId>cn.toto.maven</groupId> ?????????? <artifactId>MakeFriends</artifactId> ?????????? <version>0.0.1-SNAPSHOT</version> ?????????? <scope>compile</scope> ?????? </dependency> ? </dependencies> </dependencyManagement> <distributionManagement> ??? <repository> ??? ??? <id>releases</id> ??? ??? <name>Internal Releases</name> ??? ??? <url>http://localhost:8080/nexus-2.1.2/content/repositories/releases/</url> ??? </repository> ??? <snapshotRepository> ??? ??? <id>snapshots</id> ??? ??? <name>Internal Snapshots</name> ??? ??? <url>http://localhost:8080/nexus-2.1.2/content/repositories/snapshots/</url> ??? </snapshotRepository> ? </distributionManagement> ? </project> |
?
?
總結
以上是生活随笔為你收集整理的8.Eclipse中创建Maven Web项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 芒果节用新鲜芒果做了个大芒果造型,有人说
- 下一篇: 15斤酱块下酱用多少盐,加多少水?