Skip to content

Exporting a jar file for Release

Peter Colapietro edited this page Jun 17, 2015 · 9 revisions

Running the Maven "package" phase from the command line

mvn clean package

Creating a run configuration in Eclipse for the Maven "package" phase

A Maven run configuration for the "package" goal is necessary for taking the compiled code and packaging it in a runnable JAR. See steps with accompanying screenshots below which detail how to create one via the Project Explorer view. These steps should also be applicable to the Package Explorer view, and as with most things in Eclipse can be accomplished in multiple ways. It is left up to the reader to decided which works best for their workflow and happily accept more documentation on different ways to achieve the same result.

The screenshots documented below are from the Eclipse IDE for Java Developers packaged solution of Eclipse Luna SR2 (4.4.2). The "installed" IDE used for capturing the screenshots contains some extra plug-ins(PMD, GitHub, etc.) that are not included in the packaged solution, so your IDE might have different features. These plug-ins are not necessary to create Maven run configurations and whose inclusion in the screenshots can be safely ignored for our purposes.

Step 1. Right click on your Maven Project

exporting-a-jar-file-for-release-0

Step 2. Select "Maven Build" and create a new one.

exporting-a-jar-file-for-release-1

Step 3. Use the screenshot to create a run configuration for the package phase.

exporting-a-jar-file-for-release-2

The console view in Eclipse will display the output from running your Maven run configuration. This will detail where to find jars. The runnable jar is Makelangelo-{version.name}-jar-with-dependencies.jar NOT Makelangelo-{version.name}.jar, where {version.name} is something like v7.1.0

Example output from console view

Note some output has been omitted for brevity.

...
Tests run: 11, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ Makelangelo ---
[INFO] Building jar: /foo/bar/Makelangelo/java/target/Makelangelo-v7.1.4-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-assembly-plugin:2.5.3:single (make-assembly) @ Makelangelo ---
[INFO] Building jar: /foo/bar/Makelangelo/java/target/Makelangelo-v7.1.4-SNAPSHOT-jar-with-dependencies.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.442 s
[INFO] Finished at: 3030-03-14T15:92:32-65:35
[INFO] Final Memory: 31M/270M
[INFO] ------------------------------------------------------------------------

Further readings

It is recommend to read over this tutorial.