How do I make a JAR from a .java file?

前端 未结 7 1125
太阳男子
太阳男子 2020-11-29 17:55

I was writing a simple program using a Java application (not application that has projects, but application within a project; .java) that has a single frame. Both o

7条回答
  •  既然无缘
    2020-11-29 18:18

    Perhaps the most beginner-friendly way to compile a JAR from your Java code is to use an IDE (integrated development environment; essentially just user-friendly software for development) like Netbeans or Eclipse.

    • Install and set-up an IDE. Here is the latest version of Eclipse.
    • Create a project in your IDE and put your Java files inside of the project folder.
    • Select the project in the IDE and export the project as a JAR. Double check that the appropriate java files are selected when exporting.

    You can always do this all very easily with the command line. Make sure that you are in the same directory as the files targeted before executing a command such as this:

    javac YourApp.java
    jar -cf YourJar.jar YourApp.class
    

    ...changing "YourApp" and "YourJar" to the proper names of your files, respectively.

提交回复
热议问题