我如何让我的项目的运行时依赖复制到目标/lib文件夹?
就像现在一样,在mvn清洁安装后,目标文件夹只包含我的项目的jar,但没有运行时依赖项。
我如何让我的项目的运行时依赖复制到目标/lib文件夹?
就像现在一样,在mvn清洁安装后,目标文件夹只包含我的项目的jar,但没有运行时依赖项。
当前回答
假设
您不希望更改pom.xml 你不想要测试范围(例如junit.jar)或提供的依赖关系(例如wlfullclient.jar)
以下是对我有效的方法:
mvn install dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=target/lib
其他回答
试试这样做:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
这是一种用于嵌入严重依赖关系的重载解决方案,但Maven的Assembly Plugin对我来说是有用的。
@Rich Seller的回答应该是有效的,尽管对于更简单的情况,你应该只需要从使用指南中摘录以下内容:
<project>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
假设
您不希望更改pom.xml 你不想要测试范围(例如junit.jar)或提供的依赖关系(例如wlfullclient.jar)
以下是对我有效的方法:
mvn install dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=target/lib
你所需要的只是在pom.xml的build/plugins里面的以下代码片段:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
当您运行时,上面的代码将在包阶段运行
mvn clean package
依赖项将被复制到代码片段中指定的outputDirectory,在本例中为lib。
如果只是偶尔这样做,则不需要更改pom.xml。简单地运行以下命令:
mvn clean package dependency:copy-dependencies
重写默认位置${project.build。目录}/依赖,添加一个名为outputDirectory的系统属性,即
-DoutputDirectory=${project.build.directory}/lib
mvn install dependency:copy-dependencies
工作为我在目标文件夹中创建的依赖目录。喜欢它!