Skip to content
Advertisement

How to create a .jar file using the terminal

I’m trying to create a .jar file using the mac terminal but am having bit of trouble. I followed the steps here but was unsuccessful. I got this error message:

JavaScript

So how exactly do you go about doing it? My java program is called Main.java and I have compiled it into a .class file. Now what do I do?

Thanks

Advertisement

Answer

1) Ensure that all necessary files are within the directory, you have opened a terminal/Command Prompt and have navigated to that directory.

2) Compile the .java class, for example HelloWorld.java with

JavaScript

3) This will produce a .class file needed for the JAR file.

4) Next create a manifest file (saved using the extension .txt) using the text editor and input the following

JavaScript

or whatever your file’s name is.

5) Next create the JAR file using this code:

JavaScript

6) Run the file:

JavaScript

If anything seems unclear consult these websites: creating a jar file and setting an applications entry point.

Hope this helps others, cheers Tom!

Edit:

Following inga’s comment it’s worth noting that in order to include multiple files in the jar you need to use the:

JavaScript

followed by

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement