11

i have made an application in JDK7, but the jre6 is still using in the market, and if i send my jar file to someone with jre6, it wont work, is there a way that application checks the jre version and if it doesn't compat then ask user to update..

asked May 16, 2012 at 6:48
3
  • Here is a link how to compare the JRE version. Commented May 16, 2012 at 7:05
  • @Crazenezz: is there a way by checking thru dos, by creating a windows batch file and virtual basic, could this be done?? if it match then it'll execute the jar?? can this be practically done wt i am saying?? Commented May 16, 2012 at 7:08
  • There is a possibility to do that in batch. You can convert the algorithm in the link that I give above and translate it with batch programming style (If you feel comfortable using that). Commented May 16, 2012 at 7:22

6 Answers 6

12

You can use System.getProperty(String key); method with "java.version" as key.

String version = System.getProperty("java.version");

Example output:

1.6.0_30

The available keys can find at here.

answered May 16, 2012 at 6:51
Sign up to request clarification or add additional context in comments.

2 Comments

will that work if jre is mismatching...cause in my case the jre file just gives the splash screen and closes itself if i use jre6.. i need some fool proof solution!!
its not showing any exception...the program wont run...i had made an exception error dialog box.....but nothing works..
2
System.getProperty("java.version")

Note: It will return current jvm's version, jvm on which this code is executing, If you have java6 & java7 installed on your computer and you are running this code on java 7 it will show you version 7

answered May 16, 2012 at 6:51

2 Comments

will that work if jre is mismatching...cause in my case the jre file just gives the splash screen and closes itself if i use jre6.. i need some fool proof solution!!
its not giving any exception....its just not running...i have made a error dialog in case of any exception....so i havent shown anything....
2
static public void main(String[] arg) throws IOException
 {
 PrintStream out = System.out;
 Properties pro = System.getProperties();
 Set set = pro.entrySet();
 Iterator<Map.Entry<String , String >> itr = set.iterator();
 while(itr.hasNext())
 {
 Map.Entry ent = itr.next();
 out.println(ent.getKey() + " -> " + ent.getValue() + "\n");
 }
}

Use System.getProperty("java.version") or System.getProperty("java.runtime.version") to get installed version of java.
The above code snipped helps you find out more details such as java vendor name , OS etc.

answered May 16, 2012 at 7:02

Comments

0

here is an example that checks the version and trows an exception if the version is incorrect using System.getProperty("java.version");

answered May 16, 2012 at 6:53

2 Comments

will that work if jre is mismatching...cause in my case the jre file just gives the splash screen and closes itself if i use jre6.. i need some fool proof solution!!
I cant verify it atm but if you put this in a class that gets loaded before any jre7 specific classes are loaded it should work
0

Using Java Web Start you have a messagebox about the java version if it is not compatible with your jar. For example:

<resources>
 <j2se version="1.4+"
 href="http://java.sun.com/products/autodl/j2se" />

in the jnlp file

answered May 16, 2012 at 6:55

Comments

0

UnsupportedClassVersionError would occur if you try to run a Java file on an older version of jre compared to the version on which it was compiled.

java.lang.UnsupportedClassVersionError: Bad version number in .class file [at java.lang.ClassLoader.defineClass1(Native Method)] on running a compiled java class file.

In essence you can not run .class files that are compiled with a newer version than the JVM.

answered May 16, 2012 at 8:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.