maven:将多模块项目组装成单个jar
我有一个多模块项目,想要创建一个包含所有模块的类的单个 jar。在我的父 POM 中,我声明了以下插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>bin</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
但是,当运行 mvn assembly: assembly 时,仅包含父文件夹(空)中的源代码。如何将模块中的源代码包含到存档中?
I have a multi-module project and want to create a single jar containing the classes of all my modules. Inside my parent POM, I declared the following plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>bin</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
However, when running mvn assembly:assembly, only the source from the parent folder (empty) are included. How do I include the sources from my modules into the archive?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您正在寻找 Maven Shade 插件:
http://maven。 apache.org/plugins/maven-shade-plugin/index.html
将任意数量的依赖项打包成超级包依赖项。然后可以将其部署到存储库。
I think you are looking for the Maven Shade Plugin:
http://maven.apache.org/plugins/maven-shade-plugin/index.html
Packages up any number of dependencies into an uber package depenency. This can then be deployed to a repository.
要将所有模块中的类打包到单个 jar 中,我执行了以下操作:
创建了仅用于将所有其他模块的内容打包到单个 jar 中的附加模块。这通常被称为组装模块。尝试以与目标 jar 文件相同的方式调用此模块。
在这个新模块的 pom.xml 中,我添加了 maven-assemby-plugin。该插件打包所有类并将它们放入单个文件中。它使用额外的配置文件(步骤 4)。
3.在这个新模块的 pom.xml 中,我还添加了对所有其他模块(包括父 pom)的依赖项。只有依赖项中包含的模块才会打包到目标 jar 文件中。
4.最后我在程序集模块中创建了程序集描述符(文件:src/main/assemble/framework_bin.xml)
To package classes from all modules to a single jar I did the following:
Created additional module that is used only for packing contents of all other modules to a single jar. This is usually reffered to as a assembly module. Try calling this module same as target jar file.
In pom.xml of this new module i added maven-assemby-plugin. This plugin packages all classes and puts them in single file. It uses additional configuration file (step 4.)
3.In pom.xml of this new module I also added dependencies to all other modules including parent pom. Only modules included in dependencies will be packed in target jar file.
4.Finally i created assembly descriptor in assembly module (file: src/main/assemble/framework_bin.xml)
预定义的 bin 在这里不起作用。您必须使用类似于预定义
bin
描述符的自定义描述符,但声明moduleSet
以包含您的项目模块。The predefined
bin
won't do the trick here. You'll have to use a custom descriptor similar to the predefinedbin
descriptor but that declaresmoduleSet
to include your project modules.