create a JAVA Standalone executable application to run on different platforms without any Installation

后端 未结 4 1512
北恋
北恋 2021-02-14 19:24

I have created a run time image for my Java application using jlink and I would like to be able to ship my app as an executable to different platforms.

Ideally, it woul

4条回答
  •  春和景丽
    2021-02-14 19:51

    Yes, as of Java 8 there are two ways of doing this, using the javapackager tool, or the JavaFX Ant Tasks (which aren't actually specific to JavaFX, and are provided with the Java 8 JDK).

    Here's an example of packaging an application as a Jar, setting the main-class and classpath attributes, and copying all the dependencies into a folder, using Maven.

    
            
                maven-dependency-plugin
                
                    
                        package
                        
                            copy-dependencies
                        
                        
                            ${project.build.directory}/lib
                        
                    
                
            
            
                maven-jar-plugin
                3.2.0
                
                    
                        
                            true
                            ${project.groupId}.${project.artifactId}.DemoCLI
                        
                    
                
            
    
    

    And here is the Ant build file to package the standalone application (exe for Windows, .app and .dmg on OS X, .deb and .rpm on Linux).

    
    
    
    
    
    
        
        
    
        
        
    
       Using Java from ${java.home}
    
        
    
            
            
    
            
            
    
            
           
                
                
           
    
            
            
    
                
                
    
            
    
        
    
        
        
            
            
        
    
    
    

提交回复
热议问题