我正在尝试使用Maven创建一个可执行jar文件,该文件包含一个单独目录中的依赖项。我已经看到很多关于创造“uberjar”的问题 - 我不希望如此。我想要的是将依赖项复制到像这样的“lib”目录中(以及带有MANIFEST.MF
条目的jar ClassPath
文件):
/myApp
myApp.SNAPSHOT-1.0.jar
/lib
hibernate.jar
log4j.jar
...
作为额外的奖励,如果我可以将/src/main/resources/*
复制到/myApp/conf
然后将整个/myApp
目录压缩到myApp.zip
中,那就太棒了。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>
${project.build.directory}/release/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/release</outputDirectory>
<resources>
<resource>
<directory>src/main/config</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/release/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
答案 0 :(得分:5)
maven依赖插件有一个复制依赖目标,可以做你想要的。
mvn dependency:copy-dependencies
有关可用选项,请参阅here。即'outputDirectory'将依赖项复制到/ lib