Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jar

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 of the files are .java so I can't write a manifest needed by the JAR.

The MyApp.java starts like a class with package, imports then public class MyApp and has a main function, but it's still .java file! I'm writing it in JDeveloper 11g if it helps.

Any ideas how to make a JAR from these files?

like image 774
user1303007 Avatar asked Mar 30 '12 10:03

user1303007


People also ask

Are .java and .jar files the same?

java files are the source-code, and . jar files contain the compressed and packaged compiled .

How do I create a runnable jar file from a Java project?

Select Java > Runnable JAR file as the export destination and click Next. On the next page, specify the name and path of the JAR file to create and select the Launch configuration that includes the project name and the name of the test class.


2 Answers

Open a command prompt.

Go to the directory where you have your .java files

Create a directory build

Run java compilation from the command line

javac -d ./build *.java 

if there are no errors, in the build directory you should have your class tree

move to the build directory and do a

jar cvf YourJar.jar * 

For adding manifest check jar command line switches

like image 110
BigMike Avatar answered Nov 03 '22 02:11

BigMike


Simply with command line:

javac MyApp.java jar -cf myJar.jar MyApp.class 

Sure IDEs avoid using command line terminal

like image 29
ab_dev86 Avatar answered Nov 03 '22 01:11

ab_dev86