是否可以重命名带有依赖项的 Maven jar?
我目前正在使用 jar-with-dependencies 程序集来创建这样的 jar。不过我的jar名字有点长。
由于 AS400 上的 RPG 程序正在使用此 jar,因此我想缩短它以使这些开发人员的生活更轻松一些。但是,除了手动之外,我还没有找到从通常的 project-name-version-classifier-jar-with-dependency.jar
重命名 jar 的方法。我想要像 project-name-version-classifier-full.jar
这样的东西,
有没有办法在基本上不复制 jar-with-dependencies 程序集描述符并将其调用为 full 的情况下执行此操作?
此外,我想继续将没有组装类路径的 jar 存储在存储库中。
我需要两件文物。带有我的分类器的罐子保存了构建所在的区域。具有所有依赖项的 jar,其中还包括区域。
project-name-version-region-full.jar
和 project-name-version-region.jar
应存储在存储库中。在第一个示例中,分类器是满区域的,在第二个示例中,分类器是区域的。后者正在发挥作用。
I'm currently using the jar-with-dependencies assembly to create such a jar. However, the name of my jar is a bit long.
Since this jar is being used by RPG programs on an AS400, I'd like to shorten it to make life a bit easier for those developers. But, other than by hand, I've not found a way to rename the jar from the usual project-name-version-classifier-jar-with-dependencies.jar
. I'd like something like project-name-version-classifier-full.jar
Is there anyway to do this without basically copying the jar-with-dependencies assembly descriptor and calling it full?
Additionally, I want to continue to have the jar without the classpath assembled stored in the repository.
I need two artifacts. The jar with my classifier holding the region which the build is for. The jar with all dependencies which also includes the region.
project-name-version-region-full.jar
and project-name-version-region.jar
should be stored in the repository. In the first example the classifier is region-full, in the 2nd it's region. The latter is working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以指定 finalName 属性来为 jar 提供所需的名称,并指定 appendAssemblyId 应为 false 以避免出现“jar-with-dependencies”后缀。
下面的配置将输出一个名为“test.jar”的 jar
更新:根据您的评论,使用内置描述符将不起作用。我相信这是由于最新版本的程序集插件中的一个错误 - 他们删除了对分类器的支持,但如果您使用内置描述符,则 id 是固定的,因此您最终会得到一个大而愚蠢的名称。
作为解决方法,您可以复制 jar-with-dependencies 描述符并修改 id。
此示例将导致程序集 ID 附加到 FinalName,因此如果您需要名称为 region-full.jar,则可以将 FinalName 指定为 region且程序集 ID 为完整。这将在目标中生成一个名为region-full.jar的文件,但请注意,它仍然会作为附加工件安装到Maven存储库中,并使用full作为分类器。只要此 id 与其他程序集的 id 不同,就不应该发生冲突。
pom 配置看起来像这样。
src/main/ assembly 中的 jar- assembly.xml 如下所示:
You can specify the finalName property to give the jar the name you want, and specify that appendAssemblyId should be false to avoid the "jar-with-dependencies" suffix.
The configuration below will output a jar called "test.jar"
Update: based on your comments, using the built-in descriptor won't work . I believe this is down to a bug in the recent versions of the assembly-plugin - they've removed support for classifiers, but the id is fixed if you use a built-in descriptor, so you end up with a big daft name.
As a workaround, you can copy the assembly descriptor used by the jar-with-dependencies descriptor and modify the id.
This example would result in the assembly id being appended to the finalName, so if you need to have a name of region-full.jar, you can specify the finalName as region and the assembly id as full. This will result in a file in target called region-full.jar, but note it will still be installed to the Maven repository as an attached artifact with full used as the classifier. As long as this id is different to that for your other assembly there should be no collision though.
The pom configuration would look like this.
and the jar-assembly.xml in src/main/assembly like this:
我想我已经找到了一种直接在 pom 中配置它的方法,而不需要单独的 jar- assembly.xml 。
它与Rich的答案基本相同,只是finalName是用artifactId和version指定的。
I think I've found a way to configure this directly in the pom without needing a separate jar-assembly.xml.
It's basically the same as Rich's answer, except the finalName is specified with the artifactId and version.
还可以使用
${project.build.finalName}
作为最终名称来覆盖原始 jar 文件:It is also possible to overwrite the original jar file by using
${project.build.finalName}
as final name:感谢这里的帖子以及对 maven 文档 的一些挖掘,我来了使用以下配置来创建一个具有自定义名称的通用一次性重新打包的可执行 jar 程序集。
在 pom.xml 中:
在 assembly.xml 中:
这将生成
MyJarName.jar
,其所有依赖项都重新打包到同一个 jar 和指定的Main-Class: karlthepagain.MyMain.
Thanks to the posts here and some digging in the maven docs I've come up with the following configuration for a general one-off repacked executable jar assembly with a custom name.
In pom.xml:
In assembly.xml:
This will produce
MyJarName.jar
with all of its dependencies re-packaged into that same jar and the specifiedMain-Class: karlthepagain.MyMain
.我要感谢 Rich 为我指明了正确的方向,但我想发布对我有用的解决方案,因为 Rich 的解决方案稍有偏差:
我的 jar- assembly.xml 看起来像这样,它允许程序集 id 更改为作为属性存储在我的配置文件中的区域:
我没有在 maven-assemble-plugin 设置中使用 FinalName 参数,因为这使用我的项目名称-版本-env-full.jar 名称(其中 env-full)构建了我的项目是分类器。
想象一下,当我得知程序集 xml 可以通过构建中的项目进行参数化时,我有多惊讶。这正是我想要的。
I'm going to give Rich the credit for pointing me in the right direction, but wanted to post the solution that worked for me as Rich's was slightly off:
My jar-assembly.xml looked like this which allowed the assembly id to change for the region which was stored as an property in my profile:
I did not use the finalName parameter in the maven-assembly-plugin settings as this built my project with my project-name-version-env-full.jar name where env-full was the classifier.
Imagine my surprise when I learned the assembly xml could be parameterized by items in the build. This was exactly what I was looking for.
这对我有用
This worked for me