Maven - Copy Some Dependency JARs into warSourceDi

2019-08-01 10:36发布

Can any Maven plugins copy one or more dependencies (although not all of them) of a .war project into its warSourceDirectory (src/main/webapp)?

I'm working on a Java web-app that will display an applet. I'd like the war project to pick the latest version of some jars (the applet's dependencies) and stick them in /src/main/webapp/, to save me having to copy them around the place.

I've thought about shading and uber-jar-ing the applet itself, but I'd like to split the jars up to save users having to download one massive jar when only one of the bits in it has changed.

1条回答
叼着烟拽天下
2楼-- · 2019-08-01 11:15

Use for this dependency:copy from Maven Dependency Plugin.

Read also example page: Copying specific artifacts

Sample configuration

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
    <execution>
        <id>copy</id>
        <phase>compile</phase>
        <goals>
            <goal>copy</goal>
        </goals>
        <configuration>
            <artifactItems>
                <artifactItem>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>3.8.1</version>
                    <type>jar</type>
                    <overWrite>false</overWrite>
                    <destFileName>optional-new-name.jar</destFileName>
                </artifactItem>
            </artifactItems>
            <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/</outputDirectory>
            <overWriteReleases>false</overWriteReleases>
            <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
    </execution>
</executions>

Copying files into src/main/webapp is bad idea. Copy file directly into target folder.

查看更多
登录 后发表回答