我想用maven创建多模块独立应用程序。
在我的情况下,我想让'Loader'项目(.jar)包含所有其他项目。但是现在我只设置了.jar文件(loader.jar,crawler1.jar ......等)
loader's .pom :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javanix.jmetalcrawler</groupId>
<artifactId>loader</artifactId>
<version>1.0</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
子项目的.pom :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javanix.jmetalcrawler</groupId>
<artifactId>Crawler-1</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.javanix.jmetalcrawler</groupId>
<artifactId>loader</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
父母的.pom :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javanix.jmetalcrawler</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>jMetalCrawler</name>
<modules>
<module>Crawler-1</module>
<module>Loader</module>
</modules>
</project>
生命周期:
P.S :
maven-assembly-plugin
(@see http://rombertw.wordpress.com/2010/05/14/maven-recipe-building-an-aggregate-jar/)答案 0 :(得分:2)
我建议像这样的项目结构:
loader (POM, multi-module)
+ loader-api (JAR)
+ crawler1 (JAR, depends on loader-api)
+ crawler2 (JAR, depends on loader-api)
+ loader-app (JAR, depends on loader-api, crawler1, crawler2.
The standalone app is built here)
通过拆分爬虫所依赖的API和应用程序本身,整个项目结构更容易管理。而且,它也更加模块化,因为我们不再将API与应用程序混合
答案 1 :(得分:0)
如果您使用“带有maven的多模块独立应用程序”是指包含其所有依赖项的自包含可执行jar,则onejar-maven-plugin可能就是您要查找的内容。有关使用示例,请参阅documentation。