說明:如果按照這種方式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
