maven 多个模块中相互的依赖

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值