How to make an executable JAR file?

后端 未结 5 1321
孤独总比滥情好
孤独总比滥情好 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:04

    Here it is in one line:

    jar cvfe myjar.jar package.MainClass *.class
    

    where MainClass is the class with your main method, and package is MainClass's package.

    Note you have to compile your .java files to .class files before doing this.

    c  create new archive
    v  generate verbose output on standard output
    f  specify archive file name
    e  specify application entry point for stand-alone application bundled into an executable jar file
    

    This answer inspired by Powerslave's comment on another answer.

提交回复
热议问题