Question

I want to create a executable jar file of a small game that i wrote in java and make it playable in any machine with simple double click like exe file. My question is do you need to install java runtime first in order for executable jar file to work or can it work on a machine without any java installed as well?

Was it helpful?

Solution

No it can't. However, clients do not require the JDK, the JRE would do. You can make your jar declare its own main class and have users double click it normally like an exe file or create a bat file in Windows.

OTHER TIPS

It requires a JRE instance to be installed on the host machine. This is because JAR files are actually executed via a command line like (in Windows):

java -jar ...

This means that somewhere on your system the java.exe executable should be reachable, either by including its folder in the PATH (Windows) or replacing java with its full path.

Also, most likely you will need to have all the runtime Java libraries to be hosted on the system, as the JAR file containing the application you want to run is not supposed to contain all the Java API libraries. They are also part of the JRE package.

My explanation is tied to Windows for the sake of examples, but it can be extended to any OS.

Do you need to install java runtime first in order for executable jar file to work?

Yes, of course. To run Java .jar files first you need to have installed at least the JRE (run time environment). The JDK (development kit) is a superset of the JRE and will also work for running .jar files.

Can it work on a machine without any java installed as well?

No, as mentioned above, at the bare minimum the JRE must be installed.

You have to have a Java runtime environment (JRE) available on the machine unless you use a tool that performs ahead-of-time compilation (AOT, which is contrast to the usual Just-In-Time). Such tools are available (such as Excelsior JET), but they have a number of downsides, including cost and the fact that a precompiled Java application is a regular executable and will only run on one operating system. I've seen some installers that will detect whether a JRE is installed and launch the Java installer for the user if not.

Yes ! of course, JRE is required and it is not compulsory for JDK to be installed. Since, the main class is defined in JRE for .jar files, it is necessary to have JRE on your machine. I tried with Windows OS.

Actually you can bundle JRE within your exe file with several java .exe wrappers. Here are few of them JSmooth, Launch4j, Jar2Exe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top