[wp_ad_camp_1]
This post demonstrates how to create an executable jar in Apache Maven
using maven-shade-plugin
plugin.
Software Requirements
- Java 8
- Eclipse Mars.2
- Maven 3.3.3 (Embedded)
Update pom.xml
Create a Maven project in Eclipse or open an existing Maven project, update your pom.xml
with the following plugin
.
[wp_ad_camp_4]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> ... <build> ... <plugins> .... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.turreta.maven.jar.ExecutableMainClass</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> ... </plugins> </build> </project> |
Package it
To package it from Eclipse
, run embedded Maven using the package goal
.
[wp_ad_camp_3]
Test Out
Depending on your current configuration, your JAVA_HOME
and PATH
may no be properly set. In this case, simply set them up on the same Windows command line window.
1 2 3 | set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_101 set PATH=%PATH%\C:\Program Files\Java\jdk1.8.0_101\bin |
There will be two (2) jar files generated. Choose the one without the original-
prefix on the file name.
[wp_ad_camp_5]
Download the Codes
https://github.com/Turreta/Maven-Create-executable-jar
[wp_ad_camp_2]