如何将所有依赖项放在runnable jar的单独文件夹中?
我正在使用mvn package
创建一个可运行的jar,其中包含所有依赖项,运行正常。 但我更喜欢将所有外部依赖项打包在一个单独的文件夹中。 那么我需要改变什么呢?
maven-assembly-plugin 2.4 jar-with-dependencies my.MainApp make-assembly package single
使用maven-dependencies-plugin
为copy-dependencies
执行指定输出目录。
org.apache.maven.plugins maven-dependency-plugin 2.5.1 copy-dependencies package copy-dependencies ${project.build.directory}/lib/
更新:
要让jar知道在哪里找到lib
文件夹,可以使用maven-jar-plugin
在manifest
中将其指定为Class-Path
值
org.apache.maven.plugins maven-jar-plugin true lib/ foo.bar.MainClass
希望这可以帮助。