简体   繁体   English

创建超级罐子时遇到困难

[英]Having difficulty creating an uber-jar

I'm trying to bundle up a java archive (JAR) with all dependencies self contained. 我试图捆绑一个Java归档文件(JAR),其中包含所有自包含的依赖项。 First I tried using the maven assembly plugin though this was missing some classes. 首先,我尝试使用maven程序集插件,尽管它缺少一些类。 The jar-with-dependencies documentation suggests using the maven-shade-plugin , which ends up missing different classes. jar-with-dependencies文档建议使用maven-shade-plugin ,最终会丢失不同的类。 I think what's happening is that multiple dependencies using the same package names seem to get skipped, so things like slf4j get skipped. 我认为正在发生的事情是,使用相同程序包名称的多个依赖项似乎被跳过,因此诸如slf4j之类的事情被跳过了。

What I'd really prefer is for the packaged jar to contain the libraries self-contained instead of repacking them. 我真正希望的是包装好的jar包含自包含的库,而不是重新打包它们。

I nearly gave up and figured I'd just use the bin descriptor for the assembly plugin which only zipped up the jar itself and no dependencies. 我差点放弃,以为我只将bin描述符用于程序集插件该插件只压缩了jar本身,没有依赖项。

NOTE : I know that others have asked similar questions, which have resulted in suggestions for using shade/assembly plugins, though none have illustrated the specific problem I am having. 注意 :我知道其他人也曾问过类似的问题,尽管没有人说明我遇到的具体问题,但也提出了使用阴影/装配插件的建议。

UPDATE : Requested by khmarbaise the following shows one POM where ALL classes get skipped. 更新 :khmarbaise请求以下显示了一个POM,其中所有类都被跳过。 Note that there is another JAR which uses the same package structure but is the localised bundle, localised bundles are included but all classes are omitted. 请注意,还有另一个JAR使用相同的包结构,但它是本地化的包,包含本地化的包,但省略了所有类。

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ddtek</groupId>
  <artifactId>openedge</artifactId>
  <packaging>jar</packaging>
  <version>10.1C04</version>
  <name>openedge</name>
  <url>http://progress.com</url>
  <dependencies>
    <dependency>
      <groupId>com.ddtek</groupId>
      <artifactId>base</artifactId>
      <version>10.1C04</version>
    </dependency>
    <dependency>
      <groupId>com.ddtek</groupId>
      <artifactId>util</artifactId>
      <version>10.1C04</version>
    </dependency>
  </dependencies>
</project>

Note that the above POM is a third-party library that does not publish to maven and only exists in our local nexus repo. 请注意,上面的POM是第三方库,不会发布到Maven,仅存在于我们的本地关系库中。

If no predefined descriptor suites your needs, you can write your own assembly. 如果没有预定义的描述符套件满足您的需要,则可以编写自己的程序集。

To include dependencies, you specify something like 要包括依赖关系,请指定类似

<dependencySets>
    <dependencySet>
      <outputDirectory>/lib</outputDirectory>
      <useProjectArtifact>false</useProjectArtifact>
      <useTransitiveDependencies>true</useTransitiveDependencies>
      <unpack>false</unpack>
       <scope>runtime</scope>
    </dependencySet>
  </dependencySets>

and in your pom something like: 在您的pom中类似:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <descriptors>
            <descriptor>assembly.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

and then customize, following your requirements. 然后根据您的要求进行自定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM