Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a JAR file using a specific JRE

Is there a way on Windows to run a JAR file using a JRE located in a specific folder? Similar to the way Eclipse looks for its JRE in some path you give to it. Either some windows executable code (C or C++) or a Batch file will do the job. Thanks!

like image 574
sol_var Avatar asked May 25 '12 16:05

sol_var


People also ask

How do I run a JAR file in JRE?

In that case, right-click on the file, select open with and choose the app that is suitable for opening the JAR file. To run it directly in the Java Runtime Environment, go to program files and click on the Java folder. Then go to jre1. 8.0_211 and open the bin to select java.exe.

Is JRE enough to run a JAR file?

If you do not need to compile code, but simply open or run the . jar files, then simply installing the Java Runtime Environment (JRE) will be enough (included in JDK).

How do I change what opens a .JAR file?

To change the default program that opens jar files, right-click the jar file, select Open With, then Choose default program. In the Open With window, click the Browse button to open the File Explorer window.

How do I run a specific class from a JAR file?

To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar. We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …]


1 Answers

A JRE directory has a bin/java.exe.

You can run a jar from that JRE simply with

<path_to_jre>/bin/java.exe -jar Executable.jar 

If you don't want to have to open a console each time, simply put the above line in a .bat file and double click on that.

like image 137
FlightOfStairs Avatar answered Oct 09 '22 03:10

FlightOfStairs