Last active
          September 12, 2016 22:13 
        
      - 
      
- 
        Save HashRaygoza/f572055c3387b709d59d25de8e23f909 to your computer and use it in GitHub Desktop. 
    Packaging an executable fat JAR with Apache Maven
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Three ways to create an executable and fat JAR with Maven : | |
| maven-jar-plugin (it doesn't add dependencies inside the final JAR, they have to be in the classpath) | |
| Don't forget it goes between the build and plugins tags. | |
| <build> | |
| <plugins> | |
| <plugin> | |
| <groupId>org.apache.maven.plugins</groupId> | |
| <artifactId>maven-jar-plugin</artifactId> | |
| <configuration> | |
| <archive> | |
| <manifest> | |
| <mainClass>{your.package.main.class}</mainClass> | |
| </manifest> | |
| </archive> | |
| </configuration> | |
| </plugin> | |
| </plugins> | |
| </build> | |
| maven-assembly-plugin (it adds all dependecies inside the final fat JAR) | |
| <build> | |
| <plugins> | |
| <plugin> | |
| <groupId>org.apache.maven.plugins</groupId> | |
| <artifactId>maven-assembly-plugin</artifactId> | |
| <configuration> | |
| <descriptorRefs> | |
| <descriptorRef>jar-with-dependencies</descriptorRef> | |
| </descriptorRefs> | |
| <archive> | |
| <manifest> | |
| <mainClass>{your.package.main.class}</mainClass> | |
| </manifest> | |
| </archive> | |
| </configuration> | |
| <executions> | |
| <execution> | |
| <phase>package</phase> | |
| <goals> | |
| <goal>single</goal> | |
| </goals> | |
| </execution> | |
| </executions> | |
| </plugin> | |
| </plugins> | |
| </build> | |
| maven-shade-plugin (it adds all dependecies inside the final fat JAR and executes shading) | |
| <plugin> | |
| <groupId>org.apache.maven.plugins</groupId> | |
| <artifactId>maven-shade-plugin</artifactId> | |
| <configuration> | |
| <transformers> | |
| <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | |
| <mainClass>{your.package.main.class}</mainClass> | |
| </transformer> | |
| </transformers> | |
| </configuration> | |
| <executions> | |
| <execution> | |
| <phase>package</phase> | |
| <goals> | |
| <goal>shade</goal> | |
| </goals> | |
| </execution> | |
| </executions> | |
| </plugin> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment