与我的主jar一起复制依赖项

时间:2018-01-03 21:04:42

标签: java maven

我正在尝试将所有依赖项与lib文件夹中的主jar并排 我已经将maven-dependency-plugin配置添加到指定outputDirectory的pom中 运行时构建成功

mvn clean package

主jar被编译和构建,但我没有看到复制的依赖项,我做错了什么?

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

maven版

C:\Users\user56>mvn -v
Apache Maven 3.5.0 (REMOVED; 2017-04-03T15:39:06-04:00)
Maven home: c:\apache-maven-3.5.0\bin\..
Java version: 1.8.0_144, vendor: Oracle Corporation

1 个答案:

答案 0 :(得分:1)

我尝试使用maven 3.5和maven-dependency-plugin 2.10进行配置,但它确实有效。依赖项将复制到<project>/target/lib。如果您使用的是旧版本,请检查您的maven版本(mvn -v)以及该插件的版本并进行升级。

[INFO] --- maven-dependency-plugin:2.10:copy-dependencies (copy-dependencies) @ myproject ---
[INFO] Copying guava-18.0.jar to /Users/user/git/myproject/target/lib/guava-18.0.jar