Two ways that Maven can package executable jars

Source: Internet
Author: User

1. Modify Pom.xml Add the following content

<Build>    <pluginmanagement>        <Plugins>            <plugin>                <groupId>Org.apache.maven.plugins</groupId>                <Artifactid>Maven-jar-plugin</Artifactid>                <Configuration>                    <Archive>                        <Manifest>                            <MainClass>Com.jimson.hellojava.main</MainClass>                            <Addclasspath>True</Addclasspath>                            <Classpathprefix>lib/</Classpathprefix>                        </Manifest>                    </Archive>                    <classesdirectory>                    </classesdirectory>                </Configuration>            </plugin>        </Plugins>    </pluginmanagement></Build>

Run MVN clean package;

2. MAVEN packages the dependent jar package together

<Build>        <Plugins>            <plugin>                <Artifactid>Maven-assembly-plugin</Artifactid>                <Configuration>                    <Archive>                        <Manifest>                            <MainClass>Com.jimson.hellojava.main</MainClass>                        </Manifest>                    </Archive>                    <Descriptorrefs>                        <Descriptorref>Jar-with-dependencies</Descriptorref>                    </Descriptorrefs>                </Configuration>            </plugin>        </Plugins>    </Build>

To package a dependent package together, you need to use the Maven-assembly-plugin plugin. It is important to note that when you use this plug-in for packaging, you are no longer using the MVN Package command, but instead use the MVN assembly:assembly command.

After successful execution, a jar package with-jar-with-dependencies end is given in the target folder. This jar contains all the dependent packages for the current project and can be executed independently.

Two ways that Maven can package executable jars

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.