Talha wrote:
Quote
I have another question related to this topic. I am creating an executable JAR through JBuilder Developer 2006, and I am wondering if there is any way of forcing it to use a specific JRE that would be bundled along with the application. I need to do this because the applications utilizes the services of the Java3D package from Sun Microsystems, which means that I had to make additions to the existing JRE. I cannot possibly expect every end-user to have a JRE supporting Java3D on their machine, if they have a JRE at all. Please advise me if there is a way around this problem.
Thanks!
Several ways to do this.
This is the easiest (but may not always work)
String s=System.getProperty("java.version");
System.out.println(s);
Of course your Java program would have to launch.
Second way is to get all of the environment variables and look for
JAVA_HOME, JRE_HOME:
java.util.Map m=System.getenv();
String java_Check_Path="";
java.util.Set set=m.keySet();
java.util.Iterator i=set.iterator();
int x=0;
while(i.hasNext()){
String name=i.next().toString();
//Look for the JAVA_HOME,JRE_HOME,SDK_HOME values
if(name.equalsIgnoreCase("JAVA_HOME")){
//do something with path info
java_Check_Path=m.get("JAVA_HOME");
}
else if (name.equalsIgnoreCase("JRE_HOME")) {
//do something with path info
java_Check_Path=m.get("JRE_HOME");
}
else if (name.equalsIgnoreCase("SDK_HOME")) {
//do something with path info
java_Check_Path=m.get("SDK_HOME");
}
Of course, your java code would have to lanch here.
It would be best to put this into a batch file (for Windows) or a .sh
file for Linux/Unix to make sure that the program(s) could launch. If
they couldn't, then you could assume no suitable Java version was
located on their desktops. Of course, using a batch or shell script
would not require that you use Java at all; you could just issue the
command: java -version. If that returned nothing back, then it is safe
to assume that no suitable Java version was located on their path
settings or that java was not installed on their desktops.