1. maven-assembly-plugin 第一种方式
<!-- maven-assembly-plugin -->
      <!-- 打包方式:mvn package assembly:single  -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.5.5</version>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.test.execute.Test</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
D:\Tools\idea\oa\test\target>java -jar test-jar-with-dependencies.jar
Hello World!
  1. maven-assembly-plugin 第二种方式
<!-- maven-assembly-plugin -->
      <!-- 打包方式:mvn package -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.5.5</version>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.test.execute.Test</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
D:\Tools\idea\oa\test\target>java -jar test-jar-with-dependencies.jar
Hello World!
  1. maven-shade-plugin
<!-- maven-shade-plugin -->
      <!-- 打包方式:mvn package -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.1</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.test.execute.Test</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
D:\Tools\idea\oa\test\target>java -jar test.jar
Hello World!
D:\Tools\idea\oa\test\target>java -jar test-1.0-SNAPSHOT-shaded.jar
Hello World!
更新于 阅读次数

请我喝[茶]~( ̄▽ ̄)~*

Jalen Chu 微信支付

微信支付

Jalen Chu 支付宝

支付宝

Jalen Chu 公众号

公众号