Release the executable jar package with MAVEN package

Source: Internet
Author: User

The project has a requirement to package the code and dependencies of the current project into a jar package, and then package the jar package with some related files into a tar

Two plugins are used here, shade and assembly,shade are responsible for generating the jar package, and assembly is responsible for packaging it into tar. The Pom.xml configuration is as follows:

    <build>        <plugins>              <plugin>                 <groupId> org.apache.maven.plugins</groupid>                 <artifactId>maven-shade-plugin</artifactId>                 <version>1.4</version>                 <executions >                     <execution>                         <phase>package</phase>                         <goals>                              <goal>shade</goal>                          </goals>                         <configuration>                              <finalname>abc-service</finalname>  //Package name                               <transformers>                                  <transformer                                      implementation= " Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer ">                                      <mainclass>com.abc.main</ mainclass>    //Main class name &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;                         </transformer>                              </transformers>                         </configuration>                      </execution>                 </executions>            </plugin >            <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactId> maven-assembly-plugin</artifactid>                 <version>2.4.1</version>                 <configuration>                     <descriptors>                          <descriptor>assembly.xml</descriptor>                     </ descriptors>                </configuration>             </plugin>             .......        </plugins ></build>

Assembly.xml defines the actions packaged as tar

<assembly>    <id>beta</id>    <formats>         <!-- zip,tar,tar.gz,tar.bz2,jar,dir,war -->         <format>tar.gz</format>    </ formats>    <!--  file sets that need to be packaged  -->    <fileSets>         <fileSet>             <directory>resource</directory>        //Related Files directory             <outputdirectory>/ </outputDirectory>        </fileSet>     </fileSets>    <files>         <file>   &Nbsp;        <source>${project.build.directory}/abc-service.jar </source>   //Source jar Package name              <outputDirectory>/</outputDirectory>             <destname>abc-service.jar</destname>     //tar Inside Jar Package Name         </file>    </files>   </assembly>

In Maven's execution goals, fill in the following:

Clean Test Package assembly:assembly




Release the executable jar package with MAVEN package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.