cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
nileshrathodn
Level 6

java version check!!

Hi all,

Suppose on computer 4 different versions of java are installed.
(1) Depending on the path of java.exe we can open command prompt go to path /jdk_version/bin/java.exe and type "java -version" and know the
particular version, But we cant extract the output of the command "java -version" into a file.

(2) Also using System.getProperty("java.lversion"); in java code we can get java version but it will return the version of the jvm that is running that
program. Or the path set to environment variable JAVA_HOME.
(3) Also following code can be used but it's not working:!!!(don't know why??)
import java.io.*;
import java.lang.*;

public class x
{

public static void main (String args[])
{
try
{
// get runtime environment and execute child process
Runtime systemShell = Runtime.getRuntime();
Process output = systemShell.exec("java -version");
// open reader to get output from process
BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
String line = null;
System.out.println("");
while((line = br.readLine()) != null )
{ System.out.println(line); } // display process output
System.out.println("");
int exitVal = output.waitFor(); // get process exit value
System.out.println("Process Exit Value : "+ exitVal);
}
catch (IOException ioe){ System.err.println(ioe); }
catch (Throwable t) { t.printStackTrace();}
}
}
*** My requirement is :***

4 or more jdk are installed on OS. depending on path of java.exe I need to find it's version.

Can anybody help please?????


Thanks in advance,
Nilesh Rathod.
Labels (1)
0 Kudos
(3) Replies
pv7721
Level 20

I suspect you need to check existing JDKs in order to know which one to use. The simple and elegant solution would be to bundle the correct version of JVM, thus insuring your setup and application will run no matter the platform (even on those which don't have installed JVMs / JDKs).
0 Kudos
nileshrathodn
Level 6

pv7721 wrote:
I suspect you need to check existing JDKs in order to know which one to use. The simple and elegant solution would be to bundle the correct version of JVM, thus insuring your setup and application will run no matter the platform (even on those which don't have installed JVMs / JDKs).


Actually my requirement is list the installed jdk (only jdk not jre) and know the version of selected jdk. I am going to bundle jdk too but also have to give the functinality if user wants to use installed jdk. But version of the jdk should be 1.5.0_15 or higher.

So I need to check the version of selected jdk.

Can you help please??

Thanks in advance,
Nilesh Rathod.
0 Kudos
nileshrathodn
Level 6

pv7721 wrote:
I suspect you need to check existing JDKs in order to know which one to use. The simple and elegant solution would be to bundle the correct version of JVM, thus insuring your setup and application will run no matter the platform (even on those which don't have installed JVMs / JDKs).


What about this issue ?????

Thanks in advance,
Nilesh Rathod.
0 Kudos