Java - SE - Application HelloWorld.jar

You can transform a Java project into a JAR file. This JAR file is a Java Archive of several Java files.

It can be executed like a program.

Let's see a way to create a JAR file, with 2 IDE such as NetBeans and Eclipse, and we will execute it with a command line tool.

Click on Clean and build main project, with NetBeans, this is the Hammer with the brooms.
With Eclipse you have to click on: File > Export > Java > Runnable JAR file > Select the project, the path and name it HelloWorld > Finish.

It will remove all old compiled files and recompile the project to build a JAR file.
A JAR file is like a ZIP archive that contains all compiled files.

OK, now go until your project directory to find a dist or a jar folder (the name you specified up above).
Inside we can see the HelloWorld.jar.

Open a shell and write it:

$ /myDirectory/HelloWorld/dist>java -jar HelloWorld.jar

Result:

$ Hello World!

You can also open this JAR file with a software of extraction such as Winrar.
Inside you will see a directory named META-INF and the HelloWorld.class file.
In the META-INF directory there is a new file named MANIFEST.MF.
This file specifies the name of the Manifest-Version, the Class-Path and the Main-Class.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.