Maven在jar中包含依赖lib而不解包依赖项?
我们正在尝试构建一个包含解包的依赖jar的客户机jar。清单应该有class-path
个依赖jar条目。下面的代码片段可以正常工作,但是罐子已经打开了-我们如何阻止罐子被打开
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
# 1 楼答案
Pascal Thivent提出的解决方案为Maven assembly插件定义了一个新的程序集。Maven assembly插件提供了默认的程序集,它们是“bin”、“jar with dependencies”、“project”和“src”,生成各种预定义的捆绑包
新的程序集必须在新的xml文件中定义,大多数情况下位于src/assemble中。然后它将被加载,而不是预定义的,如下所示:
# 2 楼答案
实际上,使用
jar-with-dependencies
进行组装会导致maven解压所有依赖项,因为${assembly.dependencySets.dependency.unpack}
在相应的组装描述符中被设置为true
一个简单的修复方法是提供一个类似于
jar-with-dependencies.xml
的程序集描述符,并将${assembly.dependencySets.dependency.unpack}
修改为false
,如下所示:EDIT:由于未知原因,使用
<unpack>false</unpack>
时的行为不完全相同,似乎有必要将<outputDirectory>/</outputDirectory>
添加到文件集,否则无法获得预期结果# 3 楼答案
您可以将依赖项作为jar文件添加到jar中:
程序集描述符。xml
pom。xml
但不幸的是,您不能在
manifest.mf
中使用Class-Path
头,请参见Adding Classes to the JAR File's Classpath: