Tuesday, November 24, 2015

compile single executable jar file with maven

Reference: http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven

There are 2 ways of doing it.

(1) To include other jars:

  
    
      
        org.apache.maven.plugins
        maven-shade-plugin
        
          
            package
            
              shade
            
          
        
        
          
            
              asia.wirecard.standalone.reconcile.ReconcileGUWID.App
            
          
          ${artifactId}-${version}-with-libs
        
      
    
  

The jar file itself contains all the classpath dependencies:
java -cp Target.jar com.package.target.App or
java -jar Target.jar

(2) To include extracted classes:

  
    
      
        maven-assembly-plugin
        
          
            
              asia.wirecard.standalone.reconcile.ReconcileGUWID.App
            
          
          
            jar-with-dependencies
          
        
        
          
            make-assembly 
            package 
            
              single
            
          
        
      
    
  

The jar file itself is executable:
java -jar Target.jar

No comments: