我正在使用项目内存储库依赖项解决方案将第三方 jar 作为依赖项包含在我的 Maven 项目中。我正在按照 this blog 上的说明进行操作为此。
现在,我希望当我将我的 Maven 项目打包到一个 jar 中时,创建的 jar 应该有一个 lib 文件夹,其中包含第三方 jar。但是,我不希望将其他依赖项打包到 jar 中。 (我不想要一个包含所有依赖项的胖 jar,我只想要一个包含一个第三方依赖项 jar 的 jar)。
我一直在尝试使用 maven-dependency-plugin 和 maven-jar-plugin,但我无法实现我想要的。
有人可以帮帮我吗?
最佳答案
您可以使用 maven-dependency-plugin
(看 here )如下所示,这个插件将提供很多选项来包含 ArtifactId(即 <includeArtifactIds>
)或 groupId(<includeGroupIds>
)等的 jar...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/
classes/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeArtifactIds>YOUR_THIRDPARTY_JAR_NAME</includeArtifactIds>
</configuration>
</execution>
</executions>
</plugin>
所以,上面的代码会添加YOUR_THIRDPARTY_JAR_NAME.jar
进入你的 final .jar
文件的 lib
文件夹。
关于java - Maven 在 jar 中打包项目中的存储库依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43247278/