Maven 1: install assembly: assembly, package all Dependencies

Source: Internet
Author: User

 

Let the compiled jar package contain all dependencies so that it can be run independently.

 

In the section called "Running the Simple Weather Program", we executed the Simple Weather application using the Maven Exec plugin. while the Maven Exec plugin executed the program and produced some output, you shouldn't look to Maven as an execution container for your applications. if you are distributing this command-line application to others, you will probably want to distribute a JAR or an archive as a ZIP or TAR 'd GZIP file. the following section outlines a process for using a predefined assembly descriptor in the Maven Assembly plugin to produce a distributable JAR file which contains the project's bytecode and all of the dependencies.

The Maven Assembly plugin is a plugin you can use to create arbitrary distributions for your applications. you can use the Maven Assembly plugin to assemble the output of your project in any format you desire by defining a custom assembly descriptor. in a later chapter we will show you how to create a custom assembly descriptor which produces a more complex archive for the Simple Weather application. in this chapter, we're re going to use the predefined jar-with-dependencies format. to configure the Maven Assembly Plugin, we need to add the following plugin configuration to our existing build configuration in the pom. xml.

Refreshing the Maven Assembly Descriptor

 

Refreshing the Maven Assembly Descriptor

 <project>
[...]
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>

 

Once you 've added this configuration, you can build the assembly by runningMvn assembly: assembly.

$ cd target$ java -cp simple-weather-1.0-jar-with-dependencies.jar com.sonatype.maven.weather.Main 100020    INFO  YahooRetriever  - Retrieving Weather Data221  INFO  YahooParser  - Creating XML Reader399  INFO  YahooParser  - Parsing XML Response474  INFO  WeatherFormatter  - Formatting Weather Data********************************* Current Weather Conditions for:  New York, NY, US   Temperature: 44   Condition: Fair    Humidity: 40  Wind Chill: 40*********************************

Thejar-with-dependenciesFormat creates a single JARFile which except des all of the bytecode fromsimple-weatherProject and the unpacked bytecode from all of the dependencies. This somewhat unconventional format produces a 9 MiB JARFile containing approximately 5290 classes, but it does provide for an easy distribution format for applications you 've developed with Maven. later in this book, we'll show you how to create a custom assembly descriptor to produce a more standard distribution.

 

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.