第一步:
创建maven webproject
注意以下一步:
第二步:
继承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> |