您的位置:首页 > 其它

Maven多模块项目新建技巧-解决公共项目install之后可以在单独模块中直接编译

2018-01-17 17:09 357 查看
说明:如果按照这种方式http://www.cnblogs.com/EasonJim/p/8303878.html,且按照常规的install方式在子项目中编译项目,那么需要先install一下parent项目,最后才能编译子项目。这种方式其实不太好,每次都intall一大堆项目,所以为了解决这种重的方式,可以只install公共模块,然后使其单独能编译子项目。

解决方式:

1、在常规新建的多模块项目(http://www.cnblogs.com/EasonJim/p/6863987.html)时,把公共模块的pom的parent节点去除即可。比如样例工程bus-core-api下的pom如下:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
  <parent>
<groupId>com.jsoft.test</groupId>
<artifactId>testproject</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.jsoft.test</groupId>
<artifactId>bus-core-api</artifactId>
<version>1.0-SNAPSHOT</version>
<name>bus-core-api</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>
</project>


去除了parent节点后是这样的:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jsoft.test</groupId>
<artifactId>bus-core-api</artifactId>
<version>1.0-SNAPSHOT</version>
<name>bus-core-api</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>
</project>


那么这样操作之后,直接install了bus-core-api之后就可以单独编译app-desktop-ui等项目。

注意:子模块去除了parent节点之后,随着而来的特性也会丢失,比如在父项目定义的配置项,那么也不能使用,比如父项目增加的包,那么在子项目也不能继承使用,只能单独自己引入。

测试工程:https://github.com/easonjim/5_java_example/tree/master/maventest/test10/testproject
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐