BJ Dela Cruz
BJ Dela Cruz

Reputation: 5354

How to check which version of Java is installed before a user tries to run an application?

If a user double-clicks on an executable JAR file, is it possible to check what version of Java that he or she has installed, and then display an appropriate message in a window that says that he or she needs to have X version of Java to run the application?

I am creating an application that requires Java 7, and if a user does not have that version installed, I would like to display a message that says that he or she needs to download and install it.

Of course, the user can type java -version, but it would be nice to display the version in a window for those who don't know how to check what version is installed. Is it possible to do so?

Or should I run some type of script to check before launching the application?

Upvotes: 4

Views: 177

Answers (2)

devang
devang

Reputation: 5516

You can get the java version by using System.getProperty("java.version")

See the documentation (http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html)

Upvotes: 2

MadProgrammer
MadProgrammer

Reputation: 347184

Check the System.getProperty("java.version")

You'll need to do some parsing, but this should give you a jumping of point

Upvotes: 3

Related Questions