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

前端 未结 4 915
无人及你
无人及你 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:43

    You should check out the Maven Appassembler plugin. You can get a lot more robust package using it than rolling your own assembly.

    It generates helpful startup scripts for Unix and Windows that allow you to set predefined JAVA VM options, commandline parameters and classpath.

    It also has a concept of configuration directory where you can copy default configurations that user can later change. You can also set the configuration directory to be available on the classpath.

    Dependencies can be saved in a Maven style "repo" or you can use a flat style "lib" directory.

    You still need the assembly plugin for creating a zip or tar archive.

    Here's an example appassembler configuration:

    
        org.codehaus.mojo
        appassembler-maven-plugin
        1.2.2
        
            
                
                    com.mytools.ReportTool
                    ReportTool
                
            
            ${project.build.directory}/ReportTool
            lib
            flat
        
        
            
                assembly
                package
                
                    assemble
                
            
        
    
    

    To get a zip archive I use the this assembly:

    
        bin
        
            zip
        
        
            
                ${project.build.directory}/ReportTool
                /
                
                    /**
                
            
        
    
    

提交回复
热议问题