Maven Package executable jar

Source: Internet
Author: User

The jar packages generated by the MVN clean package are not executable by default because the information with the main method is not added to the manifest. When you run the package using Java-jar, the error is as follows:

No main manifest attribute, in Original-helloworld-1.0-snapshot.jar

In order to generate the executable jar package, it is necessary to build the executable jar package with the help of the Maven-shade-plugin plug-in, and other functions are available at the official website, the configuration example URL is:

Http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html

Configuration Code (Pom.xml):

<Project>  ...  <Build>    <Plugins>      <plugin>        <groupId>Org.apache.maven.plugins</groupId>        <Artifactid>Maven-shade-plugin</Artifactid>        <version>2.3</version>        <executions>          <Execution>            <Phase>Package</Phase>            <Goals>              <goal>Shade</goal>            </Goals>            <Configuration>              <Transformers>                <TransformerImplementation= "Org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">                  <MainClass>Org.sonatype.haven.HavenCli</MainClass>                </Transformer>              </Transformers>            </Configuration>          </Execution>        </executions>      </plugin>    </Plugins>  </Build>  ...</Project

The key line is MainClass, which re-sets the entry address for the program to run, and the content is the class name we write.

Then rerun the MVN clean package to generate the executable jar, and when the package is executed again with the Java-jar command, the result is output normally.

Maven Package executable jar

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.