我们正在尝试构建一个客户端 jar,其中包含解压依赖 jar。并且 list 应该包含依赖 jar 的 class-path
条目。下面的代码片段有效,但 jar 已解压 - 我们如何阻止 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>
最佳答案
确实,使用 jar-with-dependencies
进行组装导致 Maven 将所有依赖项解压为 ${assembly.dependencySets.dependency.unpack}
设置为true
在相应的程序集描述符中。
一个简单的修复方法是提供类似于 jar-with-dependencies.xml
的程序集描述符。并修改${assembly.dependencySets.dependency.unpack}
至false
,像这样:
编辑:由于未知原因,使用 <unpack>false</unpack>
时的行为不完全一样,看来有必要加上<outputDirectory>/</outputDirectory>
到文件集,否则您不会得到预期的结果。
<assembly>
<id>uberjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
关于maven-2 - Maven - 在 jar 中包含依赖库而不解压依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56907218/