1、在D盘创建一个文件夹:ssm
2、在ssm文件夹下,用maven指令创建两个项目(一个java项目,一个web项目)
创建 ssm-biz 的java项目的指令如下:
mvn:archetype:create -DgroupId=com.ssm -DartifactId=ssm-biz -Dversion=1.0
具体的pom.xml文件内容如下
<groupId>com.ssm</groupId>
<artifactId>ssm-biz</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>ssm-biz</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>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
创建 ssm-webapp 的 web项目的指令如下:
mvn:archetype:create -DgroupId=com.ssm.web -DartifactId=ssm-webapp -DarchetypeArtifactId=maven-archetype-webapp -Dversion=1.0
具体的pom.xml文件如下:
<groupId>com.ssm.web</groupId>
<artifactId>ssm-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ssm-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
3、在D:\ssm文件夹下创建一个pom.xml文件,并添加如下红色的部分的内容
<groupId>com.jxau</groupId>
<artifactId>ssm</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>ssm-biz</module>
<module>ssm-webapp</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
4、再在ssm-biz 中的pom.xml中添加如下内容:(注意看红色标记的部分)
<parent>
<groupId>com.jxau</groupId>
<artifactId>ssm</artifactId>
<version>1.0</version>
</parent>
<groupId>com.jxau</groupId>
<artifactId>ssm-biz</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>ssm-biz</name>
5、同理,再在ssm-webapp中的pom.xml中添加如下内容:注意看红色的内容
<parent>
<groupId>com.jxau</groupId>
<artifactId>ssm</artifactId>
<version>1.0</version>
</parent>
<groupId>com.jxau</groupId>
<artifactId>ssm-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>ssm-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency> <!--此web项目需要依赖之前创建的ssm-biz项目,所以需要添加如下依赖-->
<groupId>com.jxau</groupId>
<artifactId>ssm-biz</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
6、以上创建好之后,先用maven的mvn clean install指令将项目打包,
然后执行mvn eclipse:myeclipse指令,这样导入到myeclipse项目中的时候,两个项目就会自动帮你关联起来了
注意:如果在ssm-biz的项目中,先添加的内容,就必须从新执行mvn clean install 然后在执行:mvn eclipse:myeclipse