How do you create a standalone application with dependencies intact using Maven?

前端 未结 4 914
无人及你
无人及你 2020-12-31 12:03

I have a desktop Java application built using Maven 2 (but I could upgrade to Maven 3 if that helps) with a number of open source dependencies. I\'m now trying to package it

4条回答
  •  无人及你
    2020-12-31 12:58

    Add the following plugins in pom.xml. Check the value at mainClass,classpathPrefix,addClasspath tags.

    
                org.apache.maven.plugins
                maven-jar-plugin
                2.4
                
                    
                        
                            org.apache.camel.spring.Main
                            lib/
                            true
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-assembly-plugin
                2.4
                
                    
                        src/assembly/some-assembly.xml
                    
                
                
                    
                        make-assembly
                        package
                        
                            single
                        
                    
                
            
    

    Create some-assembly.xml under src/assembly as below.

    
    distribution
    
        zip
    
    true
    
        
            ${project.build.directory}
            /
            
                *.jar
            
        
    
    
        
            runtime
            /lib
            false
            false
        
    
    

    Note that useProjectArtifact flag to false, unpack flag to false. If root folder inside zip file is not required,then one can make includeBaseDirectory to false.

    This will create name-version-distribution.zip file. Inside zip file, there will be folder name-version. Inside this folder, your executable jar and lib folder containing all dependency jars will be present. Check manifest.MF file of executable jar. It contains both main class and classpath information.

提交回复
热议问题