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!
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.
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).
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.
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 …]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With