Maven-在jar中包含依赖库而不解包依赖关系吗? [英] Maven - Include dependent libs in jar without unpacking dependencies?

查看:111
本文介绍了Maven-在jar中包含依赖库而不解包依赖关系吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试构建一个包含未包装依赖jar的客户端jar.并且清单应具有class-path条目到相关的jar.下面的代码片段有效,但是罐子没有打开包装-如何阻止罐子打开包装?

We're trying to build a client jar that includes unpacked dependent jar's. And the manifest should have class-path entries to the dependent jars. The snippet below works but the jars are unpacked - how can we stop the jars from being unpacked?

       <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.

Indeed, assembling using jar-with-dependencies causes maven to unpack all the dependencies as ${assembly.dependencySets.dependency.unpack} is set to true in the corresponding assembly descriptor.

一个简单的解决方法是提供类似于jar-with-dependencies.xml的程序集描述符,并将${assembly.dependencySets.dependency.unpack}修改为false,如下所示:

A simple fix would be to provide an assembly descriptor similar to the jar-with-dependencies.xml and modify ${assembly.dependencySets.dependency.unpack} to false, like this:

出于未知原因,使用<unpack>false</unpack>时的行为并不完全相同,似乎有必要将<outputDirectory>/</outputDirectory>添加到fileSet中,否则将无法获得预期的结果

For an unknown reason, the behavior when using <unpack>false</unpack> is not exactly the same and it seems necessary to add <outputDirectory>/</outputDirectory> to the fileSet or you don't get the expected result.

<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-在jar中包含依赖库而不解包依赖关系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆