如何制作一个Maven项目的“胖罐子”?

这个问题在这里已经有了答案:

  • 我怎样才能创建一个可执行的JAR与依赖使用Maven? 33个答案

  • Maven Shade Plugin做得很好。

    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>2.4.3</version>
          <executions>
            <execution>
              <phase>package</phase>
              <goals>
                <goal>shade</goal>
              </goals>
              <configuration>
                <transformers>
                  <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                    <mainClass>package.Main</mainClass>
                  </transformer>
                </transformers>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
    

    1)将Spring-boot-maven-plugin到pom.xml文件中

     <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>1.4.0.RELEASE</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    

    2)将包装更换为罐子

    <packaging>jar</packaging>
    

    3) mvn package会创建可执行的jar文件。

    链接地址: http://www.djcxy.com/p/29619.html

    上一篇: How to make a "fat jar" of a Maven project?

    下一篇: Build with Dependencies