[英]How can I get class files from Maven dependency into the target\classes folder
Is there any sort of Maven plugin that allows me to copy the class files for a dependency into the target\classes folder for my project?是否有任何类型的 Maven 插件允许我将依赖项的 class 文件复制到我的项目的 target\classes 文件夹中? Currently I have to manually open the jar file that has the dependencies extract the package that I need to copy over and then copy it into the target\class folder for my project.目前,我必须手动打开具有依赖项的 jar 文件提取我需要复制的 package,然后将其复制到我的项目的 target\class 文件夹中。
I need a way to do those ideally within the pom.xml file but I haven't been able to find a solution that works.我需要一种在 pom.xml 文件中理想地完成这些工作的方法,但我无法找到有效的解决方案。 Any help would be appreciated, Thanks.任何帮助将不胜感激,谢谢。
Use the maven-dependency-plugin.使用 maven-dependency-plugin。 Here is an example of how you can extract the content of a dependency JAR: 以下是如何提取依赖项 JAR 内容的示例:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<destFileName>optional-new-name.jar</destFileName>
<includes>**/*.class,**/*.xml</includes>
<excludes>**/*test.class</excludes>
</artifactItem>
</artifactItems>
<includes>**/*.java</includes>
<excludes>**/*.properties</excludes>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
This sounds like a terrible idea.这听起来是个可怕的主意。 If you want to include unpacked dependencies into your project, use the maven assembly plugin or the maven shade plugin.如果您想在项目中包含解压的依赖项,请使用 maven 程序集插件或 maven 阴影插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.