Java Tools Tutorials - Herong's Tutorial Examples - v6.22, by Dr. Herong Yang
"jar --main-class" - Making JAR File Executable
This section provides a tutorial example on how to use 'jar --main-class ...' command option to specify the application main class to make a JAR file executable.
You can also make a JAR file "executable", if you:
Here is what I did to add my JAR file, herong.jar, executable using the "jar --update --main-class ..." command:
herong> jar --update --verbose --file herong.jar --main-class F2C updated manifest
Now herong.jar contains a small stand-alone application. But how to execute this JAR file? That's easy. You can run a JAR file with the "java -jar" command like this:
herong> java -jar herong.jar 60.0 Fahrenheit = 60.0 Celsius = 15.555555555555555 My TempraturConvertorBean - Version 1.00
Cool. Right? But you can make it even better. You can register JAR files to be automatically opened by the "java -jar" command on Windows system to make JAR files "truly" executable. Here is what I did to make this happen.
Warning: this following tutorial modifies Windows registry database. Please do not follow it if you don't have enough knowledge about Windows system.
1. Go to Start > Run. And enter "regedit" followed by clicking OK. Registry Editor window shows up.
2. Go to [HKEY_CLASSES_ROOT\jarfile\shell\open\command]. You should see the current value like this: ("C:\Program Files\Java\jdk-17.0.1\bin\javaw.exe" -jar "%1" %*). This was added when you install JDK on your system.
3. Double click this value and change it to: ("C:\Program Files\java\jdk-17.0.1\bin\java.exe" -jar "%1" %*).
4. Open a command window and try this:
herong> herong.jar 50 Fahrenheit = 50.0 Celsius = 10.0 My TempraturConvertorBean - Version 1.00
Better. Right? You can run any JAR files by just typing their file names now.
You can also double click any JAR files on Window Explorer now. Try it and see what happens.
Table of Contents