简体   繁体   English

在WAR的WEB-INF / lib文件夹中重命名Maven依赖项

[英]Renaming Maven dependency in WAR's WEB-INF/lib folder

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. 我需要在Maven生成的WAR的WEB-INF/lib文件夹中有一个JAR依赖项x-1.0.final.jar而不是x-1.0.jar ,这是它在存储库中的名称。 What would be the best way to achieve this? 实现这一目标的最佳方法是什么?

In my POM I have: 在我的POM中,我有:

<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 . 我希望它以x-1.0.final.jar出现在WEB-INF/lib文件夹中。

It's and external dependency on Maven Central I don't have control over. 这是对Maven Central的外部依赖我无法控制。 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? 是否有我可以使用的Maven插件或者我应该开始编写自己的插件?

You can use maven-dependency-plugin to include artifact under the name that you need. 您可以使用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>

By default, maven-dependency-plugin is bound to the process-sources phase that seems just enough for your task. 默认情况下, maven-dependency-plugin绑定到process-sources阶段,这似乎足以完成您的任务。 Remember to set the scope provided for the artifact in dependencies so that it is not automatically included by the war plugin. 请记住在依赖项中provided为工件provided的范围,以便war插件不会自动包含该范围。

您可能想看看maven war插件outputFileNameMapping参数是否可以帮助您。

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: 我发现实现这一目标的方法是执行两个步骤:

  1. Use the maven-war-plugin to exclude the original jar file from the deliverable. 使用maven-war-plugin从交付项中排除原始jar文件。
  2. Use the maven-dependency-plugin to copy the original jar file to the new-named jar file and place this in the WEB-INF/lib directory. 使用maven-dependency-plugin将原始jar文件复制到新命名的jar文件中,并将其放在WEB-INF / lib目录中。

So, by way of illustration, this is how to specify the file you wish to exclude. 因此,通过说明的方式,这是指定要排除的文件的方式。 In this case x-1.0.jar : 在这种情况下x-1.0.jar:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <!-- Exclude file: x-1.0.jar from packaging -->
        <packagingExcludes>WEB-INF/lib/x-1.0.jar</packagingExcludes>
    </configuration>
</plugin>

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. 还要指定必须将文件的副本执行到新名称(x-1.0.final.jar),但这需要在打包之前运行。 This is specified by the phase: 'prepare-package': 这由阶段指定:'prepare-package':

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>copy</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>the group of the x jar</groupId>
                        <artifactId>x</artifactId>
                        <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>

In my example I wasn't hard-coding 1.0 but I think this should work for the original posters question. 在我的例子中,我没有硬编码1.0,但我认为这应该适用于原始的海报问题。

Sorry I dont understand your question fully what is the code you have for importing this jar in the POM? 对不起,我完全不明白你的问题,你在POM中导入这个jar的代码是什么?

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. 如果要导入的Jar在存储库中被调用,并且您要在POM中导入正确的文件,那么您不必担心JAR文件的命名约定。

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. 我相信您可能需要做的是重命名存储库中的文件,只需在资源管理器窗口中进入存储库用户/ .m2并跟踪文件并重命名它,注意这可能会影响其他项目。

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 我建议你做的是复制文件重命名,并使用新的工件id x-1.0.final.jar将其添加到存储库

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

fill in the <> 填写<>

Hope this helps Chris 希望这有助于克里斯

Just to add to the above answer. 只是添加到上面的答案。 This solution will work only if dependency plugin is configured outside of pluginManagement tag under build tag in your pom.xml 只有在pom.xml中的 build标记下的pluginManagement标记之外配置依赖项插件时,此解决方案才有效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven:将 war/web-inf/classes 中的类作为 jar 添加到 war/web-inf/lib - Maven: Adding classes from war/web-inf/classes as a jar to war/web-inf/lib Maven,GWT,Google Eclipse插件,在依赖项项目处于战争状态时无法将jar复制到WEB-INF / lib - Maven, GWT, Google Eclipse plugin, can not copy jar to WEB-INF/lib when dependency project is war 如何将罐子从WEB-INF / lib复制到Maven战争中的另一个文件夹 - how to copy jars from WEB-INF/lib to another folder in war in maven Maven大战并将版本号放在WEB-INF / lib中的jar中 - Maven war and put the version number in the jars in WEB-INF/lib Maven:在war / WEB-INF / lib中找不到本地依赖文件 - Maven: Local dependecy file not found into war/WEB-INF/lib Jar maven依赖从我的WEB-INF / lib中消失 - Jar maven dependency disappears from my WEB-INF/lib Maven不会在WEB-INF / lib文件夹中复制spring jars - Maven does not copy spring jars in WEB-INF/lib folder Maven构建损坏/ WEB-INF / lib文件夹中的jar文件 - Maven build corrupting jar files in /WEB-INF/lib folder 战争外部依赖覆盖 - 将 jars 从 WEB-INF/lib-new 移动到 WEB-INF/lib - War external dependency overlay - move jars from WEB-INF/lib-new to WEB-INF/lib 在 Maven 项目 POM 中输入<systempath>标签未包含在生成的战争文件 WEB-INF\lib 文件夹中</systempath> - Enteries in Maven Project POM with <systemPath> tag does not get included in the generated war file WEB-INF\lib folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM