I. Creating a Java Project
1th Step: First import the two Maven project Hello and Hellofriend created by the previous command line.
Method: Select the File-->import-->existing MAVEN projects option to select the corresponding project path to import
2nd step: The construction of Hello and hellofriend items sequentially successively
Method: Right-click the respective project Pom.xml file and select the Maven install command in run as to mount the widget to the warehouse
3rd Step: Create a third Maven project through Eclipse. Select File-->new-->other-->maven Project Options
4th step: Create a new file in Src/main/java Com.zdp.maven.MakeFriends.java
public class Makefriends {public String makefriends (String name) {hellofriend friend = new Hellofriend (); Friend.sayhellotofriend ("Litingwei"); String str = "Hey," "+friend.getmyname () +" make a friend. "; System.out.println (str); return str;}}
5th step: Create a new file in Src/test/java Com.zdp.maven.MakeFriendsTest.java
public class Makefriendstest {@Testpublic void Testmakefriends () {makefriends makefriend = new Makefriends (); String str = makefriend.makefriends ("Litingwei"); Assertequals ("Hey,john Make a friend," str);}}
6th step: Click on the root directory pom.xml add dependencies
<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>com.zdp.maven</groupid><artifactid> Makefriends</artifactid><version>0.0.1-snapshot</version><packaging>jar</packaging ><name>MakeFriends</name><url>http://maven.apache.org</url><properties>< Project.build.sourceencoding>utf-8</project.build.sourceencoding></properties><dependencies ><dependency><groupId>junit</groupId><artifactId>junit</artifactId>< Version>4.9</version><scope>test</scope></dependency><dependency><groupid >com.zdp.maven</groupid><artifactid>hellofriend</artifactid><version>0.0.1-snapshot </version><scope>compiLe</scope></dependency></dependencies></project>
7th Step: Right-click pom.xml Select Command execution in Run as
Two. Create a Web project
1th step: Create a MAVEN Web project
2nd Step: Inherit the parent, modify the Pom.xml file in the Web project as follows
<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>webs</artifactId><packaging>war</packaging> <name>webs Maven webapp</name><parent><groupid>com.zdp.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> com.zdp.maven</groupid><artifactid>makefriends</artifactid></dependency></ Dependencies></project>
3rd Step: Build a Test JSP
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><%@ page import=" com.zdp.maven.* "%><% makefriends MakeFriends =new makefriends (); Out.println (Makefriends.makefriends ("Wanglipeng"));%>
4th Step: module aggregation, modifying the 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>com.zdp.maven</groupid><artifactid>parent </artifactid><version>0.0.1-snapshot</version><packaging>pom</packaging><name >Parent</name><url>http://maven.apache.org</url><properties>< Project.build.sourceencoding>utf-8</project.build.sourceencoding></properties><modules> <module>, .... /hello</module><module>, .... /hellofriend</module><module>, .... /makefriends</module><module>, .... /webs</module></modules><dependencymanagement><dependencies><dependency>< Groupid>junit</groupid><artifactid>junit</artifactid><version>4.9</version> <scope>test</scope></dependency><dependency><groupid>com.zdp.maven</groupid>< artifactid>hello</artifactid><version>0.0.1-snapshot</version><scope>compile</ Scope></dependency><dependency><groupid>com.zdp.maven</groupid><artifactid> Hellofriend</artifactid><version>0.0.1-snapshot</version><scope>compile</scope> </dependency><dependency><groupid>com.zdp.maven</groupid><artifactid>makefriends </artifactid><version>0.0.1-snapshot</version><scope>compile</scope></ Dependency></dependencies></dependencymanagement></project>
5th Step: Modify the Web project, set automatically deployed under Tomcat
<build><finalName>web</finalName><plugins><plugin><groupId> org.codehaus.cargo</groupid><artifactid>cargo-maven2-plugin</artifactid><version>1.2.3 </version><configuration><container><containerid>tomcat5x</containerid>