Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

java - 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. 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...