使用自定义程序集描述符将类路径添加到清单
我有以下自定义程序集:
<assembly>
<id>full</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
以及以下配置部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.example.MyExample</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>./lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
根据 Maven 程序集插件的文档,这应该向清单文件添加一个类路径项,但它不起作用。如果我使用已弃用的程序集目标而不是单一目标,它确实有效。
我注意到有人提到存档部分仅适用于 jar 格式,但这就是我正在使用的。
当他们弃用 assembly: assembly 时,他们是否定义了一种正确执行此操作的新方法?我真的不喜欢使用已弃用的功能,但如果它们破坏了工作方式并且没有正确记录它,我真的不知道如何避免这种情况。
有人有如何正确执行此操作的示例吗?
I have the following custom assembly:
<assembly>
<id>full</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
And the following configuration section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.example.MyExample</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>./lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
According to the documentation on the maven assembly plugin, this should add a classpath item to the manifest file, however it does not work. If I use the deprecated assembly goal instead of single, it does work.
I noticed somewhere someone mentioned that the archive section is only available with the jar format, but that is what I'm using.
When they deprecated assembly:assembly, did they define a new way of doing this correctly? I really don't like using deprecated functionality, but if they break the way things worked and don't properly document it, I really don't know how to avoid this.
Does anyone have any examples of how to do this properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是汇编插件的一个很好的用途。 Java 不做罐子里的罐子。您可以使用 maven-jar-plugin 的配置选项将类路径添加到主 jar 的清单中,然后使用程序集插件来收集依赖项,然后将其放在 zip 或 tarball 中的主 jar 旁边。
http://maven.apache.org/shared/maven-archiver/examples /classpath.html
This is not a good use of the assembly plugin. Java doesn't do jars-in-jars. You can use the maven-jar-plugin's configuration options to add a classpath to the manifest of your main jar, and then use the assembly plugin to collect your dependencies and drop then next to your main jar in a zip or tarball.
http://maven.apache.org/shared/maven-archiver/examples/classpath.html
尝试将
maven-assemble-plugin
更新到版本 2.5 或更高版本。清单文件中意外缺少条目类路径似乎是由错误 引起的MASSEMBLY-576。该错误已在插件 2.5 版(2014 年 10 月 26 日发布)中修复。
Try updating the
maven-assembly-plugin
to version 2.5 or newer.The unexpected absence of the entry Class-Path in the manifest file seems to have been caused by the bug MASSEMBLY-576. The bug was fixed in version 2.5 of the plugin (released 26 October 2014).
您应该使用 maven jar 插件:
You should use the maven jar plugin: