How to make an executable JAR file?

后端 未结 5 1329
孤独总比滥情好
孤独总比滥情好 2020-11-21 23:41

I have a program which consists of two simple Java Swing files.

How do I make an executable JAR file for my program?

5条回答
  •  遥遥无期
    2020-11-22 00:14

    It's too late to answer for this question. But if someone is searching for this answer now I've made it to run with no errors.

    First of all make sure to download and add maven to path. [ mvn --version ] will give you version specifications of it if you have added to the path correctly.

    Now , add following code to the maven project [ pom.xml ] , in the following code replace with your own main file entry point for eg [ com.example.test.Test ].

          
                
                org.apache.maven.plugins
                maven-jar-plugin
                2.4
                
                    
                        
                        
                your_package_to_class_that_contains_main_file .MainFileName
                        
                    
                
            
    

    Now go to the command line [CMD] in your project and type mvn package and it will generate a jar file as something like ProjectName-0.0.1-SNAPSHOT.jar under target directory.

    Now navigate to the target directory by cd target.

    Finally type java -jar jar-file-name.jar and yes this should work successfully if you don't have any errors in your program.

提交回复
热议问题