Relive maven--maven Package jar

Source: Internet
Author: User
Tags pack
Preface

In the previous article on how to use Maven in Eclipse, now it's time to talk about how to use MAVEN to package the jar, after all, our project always needs to be executed, and it needs to run in an environment.


Body

The first is that we have to configure the Pom configuration file to be packaged as a jar, as follows:

	<modelVersion>4.0.0</modelVersion>
  	<groupId>sheldon.com.word</groupId>
  	< artifactid>wordtest</artifactid>
  	<packaging>jar</packaging>
	<version>0.0.1- snapshot</version>
	<name>wordtest Maven webapp</name>
	<url>http:// Maven.apache.org</url>

is to define the packaging method, and then there is a more important configuration:

  <build> <finalName>wordtest</finalName> <plugins> <plugin> <groupid& Gt;org.apache.maven.plugins</groupid> <artifactId>maven-shade-plugin</artifactId> < version>1.2.1</version> <executions> <execution> <phase>   
		            Package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <  
	                       		Transformer implementation= "Org.apache.maven.plugins.shade.resource.AppendingTransformer" >  
		                    <resource>META-INF/spring.handlers</resource> </transformer>  
		                        <transformer implementation= "Org.apache.maven.plugins.shade.resource.AppendingTransformer" > <resource&gT Meta-inf/spring.schemas</resource> </transformer> <transfor Mer implementation= "Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" > <mai   
		                Nclass>com.wordtest.main.dataremoval</mainclass> </transformer> </transformers> </configuration> </execution> </execution s> </plugin> </plugins> </build>

In this configuration, the only place we need to change is MainClass, which is the address of the class where we need to execute the function.

With these configured, we are ready to compile and pack.

Because this project I was originally in use, I do not execute MVN eclipse:clean eclipse:eclipse, directly execute mvn clean compile.

After the compilation is passed, we need to pack. The command to pack is the Mvn-dmaven.test.skip=true package.

Here, our executable jar package is packed, so let's go to the target folder under the project to find this package.

This executable jar package is already available.





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.