我的产品中有多个 Java 项目(打包到 jar 中),它们有一个将它们组合为模块的 pom
。每个项目都有不同的依赖项,它们的组合依赖项在父 pom
中定义。我想准备生产输出并执行以下操作:
- 将我的所有 jar 部署(复制)到一个位置
- 将所有项目中的第 3 方 jar 复制到不同的单个文件夹
- 将所有项目的配置文件(位于 src/main/resources 下)复制到第三个文件夹。
有人知道一种方法可以做到这一点,而不必为所有项目手动复制上述每个内容吗?我还希望我 future 的项目能够支持此部署过程,而不必过于努力和具体。
最佳答案
为此,您需要使用 Maven 程序集插件 - 以下是压缩分发的示例(在生产环境中,您需要解压缩):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>${project.basedir}/src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
和汇编 XML
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>${env}</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>com.mycompany:ear-project</include>
<include>com.mycompany:jnlp-project</include>
</includes>
<outputDirectory>libs</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>target/docbook/pdf</directory>
<includes>
<include>index.pdf</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
请注意,对于您的 2 个项目(EAR、JNLP),您可以通过 outputDirectory 配置放置依赖项。
关于java - 在 Maven 中部署用于生产的 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11754119/