Maven Package Executable Jar method

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/johnnywww/article/details/7964326

1. Modify Pom.xml Add the following content

            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId> maven-jar-plugin</artifactid>                <version>2.4</version>                <configuration>                    <archive>                        <manifest>                            <addClasspath>true</addClasspath>                            < Classpathprefix>lib/</classpathprefix>                            <mainClass>com.sysware.HelloWorld</mainClass>                        </manifest>                    </archive>                </configuration>            </plugin>

Run the MVN clean package to

2. Add the following in Pom.xml

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>mav En-assembly-plugin</artifactid> <version>2.3</version> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorref>jar-with-d                        Ependencies</descriptorref> </descriptorRefs> <archive> <manifest> <mainclass>com.juvenxu.mvnbook.helloworld.helloworld</ma inclass> </manifest> </archive> </configuration > <executions> <execution> <id>make-assembly                            </id> <phase>package</phase> <goals>                <goal>assembly</goal> </goals> </execution> </executions> </plugin>

Run MVN assembly:assembly

3.

<build> <finalName>...</finalName> <sourcedirectory>src/main/java</sourcedirector Y> <resources> < Copy!--control resource Files--<resource> <director            Y>src/main/resources</directory> <targetPath>${project.build.directory}</targetPath>            </resource> </resources> <plugins> <!--set source file encoding-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>m Aven-compiler-plugin</artifactid> <configuration> <defaultlibbundledir&gt ;lib</defaultlibbundledir> <source>1.6</source> <target>1.6</target> <encoding>utf-8</encoding> </configuration> </plugin> <!--packaging jar files, configure manifest                , add the Lib package to the jar dependency-<plugin> <groupId>org.apache.maven.plugins</groupId>                    <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainclass>                Monitormain</mainclass> </manifest> </archive>                </configuration> </plugin> <!--copy-dependent jar packages to the Lib directory--<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>maven-dependency-plugi n</artifactid> <executions> <execution> <id&                            Gt;copy</id> <phase>package</phase> <goals>                        <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/Lib</outputDirectory> </configuration> </execution>                </executions> </plugin> <!--troubleshoot encoding problems with resource files--<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>maven-resources-plugin</ Artifactid> <version>2.3</version> <configuration> <encoding>utf-8</encoding> </configuration> </plugin> <!--packaging the source file as a jar file--&            Gt <plugin> <artifactId>maven-source-plugin</artifactId> <version>2.1</version> <configuration> <attach>true</attach> <encoding>utf-8</encoding> </configuration> <executions> <execution                            > <phase>compile</phase> <goals>                <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

4.

<build> <resources> <resource> <targetpath>${project.build.direct Ory}/classes</targetpath> <directory>src/main/resources</directory> <fi Ltering>true</filtering> <includes> <include>**/*.xml</include> </includes> </resource> </resources> &LT;PL                Ugins> <plugin> <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.6</source> <target>1.6</targe t> <encoding>UTF-8</encoding> </configuration> </plug in> <plugin> <groupId>org.apache.maven.plugins</groupId> &lt ;artifactid>maven-shade-plugin</artifactid> <version>2.0</version> <                        Executions> <execution> <phase>package</phase> <goals>                            <goal>shade</goal> </goals> &L                                    T;configuration> <transformers> <transformer                                    implementation= "Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" >                                <mainClass>com.test.testguava.app.App</mainClass> </transformer> <transformer implementation= "or G.apache.maven.plugins.shade.resource.appendingtransformer "> <resource>applica Tioncontext.xml</resource> </transformer> </trans                            Formers> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedclasSifiername>executable</shadedclassifiername> </configuration> &lt ;/execution> </executions> </plugin> </plugins> </build>

Maven Package Executable Jar method

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.