Friday, December 5, 2014

Using application's own JRE and not System provided JRE

I have created a simple application that checks and displays your current jre version. I want it to run with same jre it is compiled with, regardless of what versions of jre other clients are using in their PC. What am I trying to say is,
Suppose I created this application using java 1.8.0. and I am using same version of java in my PC. And my friend is currently using java 1.8.0_25…  In my PC, application displays java version 1.8.0. And in my friend’s PC it displays java version 1.8.0_25.
Now what I want to do is send my jre 1.8.0 along with application and make that application use jre provided by me and not by my friend’s PC. Now the application shows version 1.8.0 on both computers. No matter even if you run it in PC containing java 7, it will still show java 8. I hope you are getting me (Sorry for bad English).

Here's pictures to make it more clear:


Here, application is running on System provided JRE i.e, JRE 1.8.0_25




Along with my application I am sending my own JRE. i.e JRE 1.8.0
I want my application to run on jre 1.8.0 and not on 1.8.0_25.



Solution:

1. For .jar files through command



C:\user\yourFolderContainingAppAndJre8Folder>jre8\bin\java -jar yourApp.jar

This will do the trick. Output is given below:







2. If you are creating .exe
Launch4j can help you: Simply give your folder name as shown i figure.






































Create your exe file:

Double click your exe and output is same as above.