简体   繁体   English

Maven的Shade插件生成的罐子有什么区别?

[英]What is the difference between the jars produced by Maven's Shade plugin?

In my Maven project, I have tried the maven-shade-plugin to produce an uber jar when I run mvn package . 在我的Maven项目中,当我运行mvn package时,我尝试使用maven-shade-plugin来生成超级jar。 As a result, I get three jars in my target directory: 结果,我在目标目录中获得了三个jar:

original-hello-world-0.1.0-SNAPSHOT.jar
hello-world-0.1.0-SNAPSHOT.jar
hello-world-0.1.0-SNAPSHOT-shaded.jar

I understand that first jar is the output of packaging without including dependencies. 我知道第一个jar是包装的输出而不包括依赖。 But the both the second and the third jars include dependencies and seem to be completely identical (they both have the same file size). 但是第二个和第三个罐子都包含依赖关系并且看起来完全相同(它们都具有相同的文件大小)。

Is there supposed to be a difference between the second and third jars? 第二罐和第三罐之间应该有区别吗? If so, what is it? 如果是这样,它是什么? Otherwise, why are two identical jars being produced? 否则,为什么要生产两个相同的罐子?

Here is my pom file: 这是我的pom文件:

<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>mygroup</groupId>
  <artifactId>myproject</artifactId>
  <packaging>jar</packaging>
  <version>0.1.0-SNAPSHOT</version>
  <name>hello-world</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.7</java.version>
    <main.class>org.example.HelloWorld</main.class>

    <maven.compiler.target>${java.version}</maven.compiler.target>
    <maven.compiler.source>${java.version}</maven.compiler.source>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.jgrapht</groupId>
      <artifactId>jgrapht-core</artifactId>
      <version>0.9.0</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- To build executable jar -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Main-Class>${main.class}</Main-Class>
                  </manifestEntries>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- To use Maven to run main class -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.3.2</version>
        <executions>
          <execution>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>${main.class}</mainClass>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

I copied your pom into a project of mine and only got two jars created when I ran mvn package . 我将你的pom复制到我的一个项目中,当我运行mvn package时,只创建了两个罐子。

Are you sure the "hello-world-0.1.0-SNAPSHOT-shaded.jar-shaded" jar is not the output of a previous maven run? 你确定“hello-world-0.1.0-SNAPSHOT-shaded.jar-shaded”jar不是以前maven运行的输出吗? Please try a mvn clean package and check what lands in the target folder. 请尝试mvn clean package并检查目标文件夹中的内容。

If you would like an additional jar with the "-shaded" tag you can add the following to your pom in the shade plugin configuration: 如果您想要一个带有“-shaded”标签的额外jar,您可以在shade插件配置中将以下内容添加到您的pom中:

<shadedClassifiedName>shaded</shadedClassifiedName>

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

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