Every Java programmer knows - or should known - that it is possible to create a runnable Java package archive (JAR), so that in order to launch an application it is enough to specify the jar file name on the Java interpreter command line along with the -jar
parameter. For example:
There are plenty of tutorials showing how to implement this feature using Ant, Maven, Eclipse, Netbens, etc.
Anyway in its basic form, it just requires to add a MANIFEST.MF
file to the jar package. The manifest must contain an entry Main-Class
that specifies which is the class defining the main method for your application. For example:
Right-click the JAR file and select Open with from the context menu. Then select Choose another app and then select it to open with Java Platform SE binary. Check the option Always use this app to open Jar files. Then press OK to continue.
But this still requires your users to invoke the Java interpreter with the -jar
option. There are many reasons why it would be preferable to have your app runnable by simply invoking it on the terminal shell like any other command.
Here comes the protip!
This technique it is based on the ability to append a generic binary payload to a Linux shell script. Read more about this here: http://www.linuxjournal.com/content/add-binary-payload-your-shell-scripts
Taking advantage of this possibility the trick is just to embed a runnable jar file into a Bash script file. The script when executed will launch the Java interpreter specifying itself as the jar to run. Too complex? Much more easier to do in practice, than to explain!
Let's say that you have a runnable jar named helloworld.jar
Copy the Bash script below to a file named stub.sh
Than append the jar file to the saved script and grant the execute permission to the file resulting with the following command:
That's all!
Now you can execute the app just typing helloworld.run
on your shell terminal.
The script is smart enough to pass any command line parameters to the Java application transparently. Cool! Isn't it ?!
In the case your are a Windows guy, obviously this will not work (except you will run a Linux compatibility layer like Cygwin).
Anyway exist tools that are able to wrap a Java application into a native Windows .exe
binary file, producing a result similar to the one explained in this tutorial. See for example http://launch4j.sourceforge.net/
JAR files are commonly used on Windows computers. Hence, do you know how to run .JAR files on Windows 10? This post from MiniTool shows how to run JAR files on Windows 10. In addition, you can visit MiniTool to find more Windows tips and solutions.
A JAR is a package file format typically used to aggregate many Java class files and associated metadata and resources, such as text, images,etc. into one file for distribution. JAR files are archive files that include a Java-specified manifest file. They are built on the ZIP format and typically have a .jar file extension.
However, do you know how to run .JAR files on Windows 10? If no, keep on your reading, and the following part will show you how to run JAR files.
In this part, we will show you how to run .JAR files with several different ways.
The first way you can try to open JAR files is to add Java to Windows. Without it, Java apps will not run on Windows and the JAR files also will not be opened.
So, in order to run .JAR files, you need to add JAVA to Windows. Now, here is the tutorial.
After all steps are finished, you can run .JAR files through the JAVA app.
In order to run JAR files, you can also choose to run it through the JAVA Platform SE Binary.
Now, here is the tutorial.
After all steps are finished, you can open JAR files on Windows 10 through the JAVA Platform SE binary.
Besides the above method, you can also run .JAR files through the Command Prompt.
Now, here is the tutorial.
Then, it will open the executable JAR file so long as it contains manifest file to specify the applications entry point.
As for how to run JAR files, you can use the third-party JAR executor and there are various JAR executors on the market. So, in order to run the JAR file, you can download a third-party JAR executor. After that, you can open the JAR file successfully.
To sum up, as for how to run.JAR files, this post has introduced 4 ways. So, if you want to run .Jar files on Windows 10, you can try these ways. If you have any better idea to run .JAR files, you can share it in the comment zone.