Maven:将第三方jar的导出jar添加到manifest中的classpath [英] Maven: Export jar with 3rd-party jars added to classpath in manifest
问题描述
我正在使用Eclipse 开发 Java maven项目,并希望导出包含所有引用库的jar 。这些引用的库属于以下两个类别之一:
I am developing a Java maven project with Eclipse and want to export a jar that includes all referenced libraries. These referenced libraries fall into one of these two categories:
-
它们是显式(或隐式) 依赖于
pom.xml
They are explicit (or implicit) dependencies in the
pom.xml
我有一些库不能作为maven工件并将它们放在/ lib中(并将它们添加到Eclipse中的构建路径中)
I have some libraries not available as maven artifacts and have put them in /lib (and added them to the build path in Eclipse)
有 maven-assembly-plugin
,适用于1)。但是,我无法找到包含非maven依赖关系的maven插件,例如/ lib中的所有jar
。
There's the maven-assembly-plugin
, which works fine for 1). However, I'm unable to find a maven plugin that also includes non-maven-dependencies, e.g. "all jars in /lib"
.
然后是Eclipse FatJar
插件,哪种工作,但自2009年以来一直没有更新,所以它似乎没有维护。另外我更喜欢我可以在 pom.xml
中直接指定的导出方法。
Then there's the Eclipse FatJar
plugin, which sort of works, but hasn't been updated since 2009, so it seems unmaintained. Also I prefer an export method that I can directly specify in the pom.xml
.
任何人都可以指向我导出所有引用的库的 maven
插件等,包括案例2中的那些?)?这只需要将它们放在jar中并在manifest的类路径中引用它们。
Can anyone point me to a maven
plugin or the like to export all referenced libraries, including those from case 2) ? That only needs to involve putting them in the jar and referencing them in the manifest's classpath.
谢谢!
推荐答案
我认为处理此问题的最佳方法是将自定义库包含到本地maven存储库中。现在您可以将库作为maven依赖项包含在内,并且可以使用maven-assembly-plugin导出pom中指定的所有依赖项。
I think the best way to handle this is to include your custom libs into a local maven repository. Now you can inlcude your libraries as maven dependencies and you can export all your dependencies specified in your pom with the maven-assembly-plugin.
这是一个教程,如何把你的lib放到maven的本地存储库中,在你的pom中使用它。 http://www.mkyong。 com / maven / how-to-include-library-manully-into-maven-local-repository /
Here is a tutorial, how to put your libs into a local repository in maven to use it in your pom. http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/
在你的pom.xml中:
And in your pom.xml:
<!-- setup jar manifest to executable with dependencies -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>your.main.class</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
这篇关于Maven:将第三方jar的导出jar添加到manifest中的classpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!