maven多模块开发配置

来源:互联网 发布:saas软件租用模式合同 编辑:程序博客网 时间:2024/06/06 23:24

一:maven的多模块开发

maven module 和 maven project的关系!多模块中, maven project是顶级的父maven项目, maven module是子maven项目(模块)。

1.新建多模块maven项目

资源地址:http://download.csdn.net/detail/changerzhuo_319/9728040


2. 在父pom中配置每个模块都需要的jar包等其他配置信息

jar:能直接被子项目继承的jar配置

  <!-- 在父pom中的dependencies标签中的jar配置, 子pom会直接继承 -->  <dependencies>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>3.8.1</version>    </dependency>  </dependencies>


jar:不能直接被子项目继承, 需要在子pom中指定groupId,artifactId,不需要配置version

<!--   父pom.xml中的配置dependencyManagement中的jar,子pom中不会直接继承,   需要在子pom中配置相应jar包的groupId、 artifactId,不需要配置version,   子pom才会自动引用父pom中这个jar的配置 。  主要配置不是所有模块都依赖的jar,且可控制不同模块中到该jar的版本一致  -->  <dependencyManagement>    <dependencies>      <dependency><groupId>maven.study</groupId><artifactId>demo.interface</artifactId><version>0.0.1-SNAPSHOT</version>      </dependency>   </dependencies>  </dependencyManagement>

  <!-- 子pom中,引用父pom中dependencyManagement下的jar, 不需要指定version, 下面案例引用的是接口子模块,可以直接引用 -->  <dependencies>  <dependency>  <groupId>maven.study</groupId>                <artifactId>demo.interface</artifactId>  </dependency>  </dependencies>

3.在父pom中指定jdk编译版本, 保存后每个子项目都需要更新maven的项目(右键-->maven-->update object configuration  不同版本的eclipse可能不一样,多次尝试下)

  <build> <plugins><!-- 指定jdk的编译版本,只能指定大版本,如:1.7, 不能指定具体的小版本,如:1.7.0_67 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins>  </build>







0 0
原创粉丝点击