重命名 WAR 的 WEB-INF/lib 文件夹中的 Maven 依赖项
我需要在 Maven 生成的 WAR 的 WEB-INF/lib
文件夹中有一个 JAR 依赖项 x-1.0.final.jar
而不是 x-1.0.jar
,这是它在存储库中的名称。实现这一目标的最佳方法是什么?
在我的 POM 中,我有:
<dependency>
<groupId>foo</groupId>
<artifactId>x</artifactId>
<version>1.0</version>
</dependency>
我希望它以 x-1.0.final.jar
的形式出现在 WEB-INF/lib
文件夹中。
它和对 Maven Central 的外部依赖我无法控制。另外,我不想强迫每个使用它的人将依赖项重新部署到他们的本地存储库。
是否有我可以使用的 Maven 插件,或者我应该开始编写自己的插件?
I need to have a JAR dependency in the Maven generated WAR's WEB-INF/lib
folder as x-1.0.final.jar
instead of x-1.0.jar
, which is the name it has in the repository. What would be the best way to achieve this?
In my POM I have:
<dependency>
<groupId>foo</groupId>
<artifactId>x</artifactId>
<version>1.0</version>
</dependency>
I want this to appear in the WEB-INF/lib
folder as x-1.0.final.jar
.
It's and external dependency on Maven Central I don't have control over. Also I don't want to force everyone using this to redeploy the dependency to their local repositories.
Is there a Maven plugin that I could utilize or should I start coding my own?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
maven-dependency-plugin
将工件包含在您需要的名称下。默认情况下,
maven-dependency-plugin
绑定到process-sources
阶段,这似乎足以满足您的任务。请记住为依赖项中的工件设置provided
范围,以便war
插件不会自动包含它。You can use
maven-dependency-plugin
to include artifact under the name that you need.By default,
maven-dependency-plugin
is bound to theprocess-sources
phase that seems just enough for your task. Remember to set the scopeprovided
for the artifact in dependencies so that it is not automatically included by thewar
plugin.您可能想查看 outputFileNameMapping maven war 插件 的参数可以帮助你。
You may want to see if the outputFileNameMapping parameter of maven war plugin can help you.
我知道我正在回复旧线程,但我需要执行上述操作并发现该线程很有帮助。我发现实现此目的的方法是执行两步过程:
因此,作为说明,这就是指定要排除的文件的方法。在本例中 x-1.0.jar :
还指定必须将文件复制到新名称 (x-1.0.final.jar),但这需要在打包发生之前运行。这是由阶段指定的:'prepare-package':
在我的示例中,我没有硬编码 1.0,但我认为这应该适用于原始海报问题。
I know that I'm replying to an old thread, but I needed to perform the above and found this thread helpful. The way I found to achieve this was to perform a 2 step process:
So, by way of illustration, this is how to specify the file you wish to exclude. In this case x-1.0.jar :
Also specify that a copy must be performed of the file to the new name (x-1.0.final.jar) but this needs to run BEFORE packaging occurs. This is specified by the phase: 'prepare-package':
In my example I wasn't hard-coding 1.0 but I think this should work for the original posters question.
抱歉,我不完全理解你的问题,你在 POM 中导入这个 jar 的代码是什么?
如果您希望导入的 Jar 在存储库中被称为该 Jar,并且您正在 POM 中导入正确的文件,那么您不必担心 JAR 文件的命名约定。
我相信您可能需要做的是重命名存储库中的文件,您只需在资源管理器窗口中进入 Repository Users/.m2 并跟踪文件并重命名即可完成此操作,请注意,这可能会对其他项目产生影响。
我建议您做的是复制文件重命名并将其添加到存储库中,并使用新的工件 ID x-1.0.final.jar
填写 <>
希望这有帮助
克里斯
Sorry I dont understand your question fully what is the code you have for importing this jar in the POM?
If the Jar you wish to import is called that in the repository and you are importing the correct file in your POM then you shouldn't have to worry about naming conventions of the JAR file.
What i believe you may have to do is rename the file in the repository you can do this simply by going into the Repository Users/.m2 in a explorer window and tracking down the file and renaming it, note this may have implications on other projects.
What i suggest you do is copy the file rename it and add it to the repository with the new artifact id x-1.0.final.jar
fill in the <>
Hope this helps
Chris