Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Determining version of JRE programmatically
Determining version of JRE programmatically [message #1006237] Wed, 30 January 2013 09:43 Go to next message
Anna C. is currently offline Anna C.
Messages: 2
Registered: January 2013
Junior Member
I'm trying to verify the version of the JRE chosen by the user for a Java Project before launch (in runtime it will have to use additional files compiled by a specific version, so the check is needed to see if they are compatible).

I know I can check the default one using system properties, but the user might have several and defined a different one for the project. I can also get the name of the JRE within Eclipse but that is user defined, so doesn't work.

Through the classpath I can't get information of the location to do a system call with java -version on the specific folder, because it uses JRE_Container. Through VMInstall it only gives me the default one Eclipse is using.

Anyone has ever encountered this problem? Any help would be much appreciated.
Re: Determining version of JRE programmatically [message #1006317 is a reply to message #1006237] Wed, 30 January 2013 14:29 Go to previous messageGo to next message
Michael Rennie is currently offline Michael Rennie
Messages: 65
Registered: July 2009
Location: Canada
Member
If you have a handle to the Java project you want the VM install infos from, the following snippet should get you what you are looking for:

try {
IVMInstall vm = JavaRuntime.getVMInstall(javaproject);
if(vm instanceof IVMInstall2) {
IVMInstall2 vm2 = (IVMInstall2) vm;
String version = vm2.getJavaVersion();
//do something with version
}
}
catch(CoreException ce) {
//handle exception
}
Re: Determining version of JRE programmatically [message #1006321 is a reply to message #1006317] Wed, 30 January 2013 15:04 Go to previous message
Anna C. is currently offline Anna C.
Messages: 2
Registered: January 2013
Junior Member
Thank you so much, that worked perfectly!
Previous Topic:How to use Cansole in Java EE IDE
Next Topic:Need help to integrate a vendor's Javadoc to Eclipse
Goto Forum:
  


Current Time: Sat Aug 30 04:24:16 EDT 2014

Powered by FUDForum. Page generated in 0.06255 seconds