在WAR的WEB-INF / lib文件夹中重命名Maven依赖项 [英] Renaming Maven dependency in WAR's WEB-INF/lib folder
问题描述
我需要在Maven生成的WAR的 WEB-INF / lib
文件夹中有一个JAR依赖项 x-1.0.final.jar
而不是 x-1.0.jar
,这是它在存储库中的名称。实现这一目标的最佳方式是什么?
在我的POM中我有:
<依赖性>
< groupId> foo< / groupId>
< artifactId> x< / artifactId>
< version> 1.0< / version>
< / dependency>
我希望它出现在 WEB-INF / lib
文件夹为 x-1.0.final.jar
。
它与Maven Central I的外部依赖关系无法控制。此外,我不想强迫所有人使用它将依赖项重新部署到他们的本地存储库。
是否有我可以使用的Maven插件或者我应该开始编码我的拥有?
您可以使用 maven-dependency-plugin
来包含您需要的名称下的工件。
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-dependency-plugin< / artifactId>
< executions>
< execution>
< goals>
< goal> copy< / goal>
< / goals>
< configuration>
< artifactItems>
< artifactItem>
< groupId> foo< / groupId>
< artifactId> x< / artifactId>
< version> 1.0< / version>
< type> jar< / type>
< outputDirectory> $ {project.build.directory} / $ {project.build.finalName} / WEB-INF / lib< / outputDirectory>
< destFileName> x-1.0.final.jar< / destFileName>
< / artifactItem>
< / artifactItems>
< / configuration>
< / execution>
< / executions>
< / plugin>
默认情况下, maven-dependency-plugin
绑定到 process-sources
阶段,这似乎足以完成您的任务。请记住为依赖项中的工件设置范围提供
,以便 war
插件不会自动包含它。 / p>
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?
You can use maven-dependency-plugin
to include artifact under the name that you need.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>foo</groupId>
<artifactId>x</artifactId>
<version>1.0</version>
<type>jar</type>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
<destFileName>x-1.0.final.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
By default, maven-dependency-plugin
is bound to the process-sources
phase that seems just enough for your task. Remember to set the scope provided
for the artifact in dependencies so that it is not automatically included by the war
plugin.
这篇关于在WAR的WEB-INF / lib文件夹中重命名Maven依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!