Maven 将 Target 中生成的 JAR 复制到外部文件夹

问题描述 投票:0回答:2
java maven netbeans pom.xml
2个回答
4
投票

使用maven-dependency-plugin

以下文档有一个示例,其中他们将刚刚构建的工件复制到自定义位置。

https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html(在页面中搜索“依赖项:复制目标也可用于将刚刚构建的工件复制到如果需要,可以自定义位置”)


0
投票

@Deadron 答案是正确的。我只是在这里复制正确的代码片段(有一些小的改进)以供更好的参考。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.6.1</version>
    <executions>
        <execution>
            <id>copy</id>
            <phase>package</phase>
            <goals>
                <goal>copy</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <artifactItems>
            <artifactItem>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <version>${project.version}</version>
                <type>${project.packaging}</type>
                <overWrite>true</overWrite>
                <outputDirectory>/my/install/path</outputDirectory>
                <destFileName>MyDestJar.jar</destFileName>
            </artifactItem>
        </artifactItems>
    </configuration>
</plugin>
© www.soinside.com 2019 - 2024. All rights reserved.