force java version

T

tiewknvc9

is there a way to require a certain java version (or better) on the
users machine?
 
O

Oliver Wong

tiewknvc9 said:
is there a way to require a certain java version (or better) on the
users machine?

You could politely ask the user to ensure that they have a certain
version of Java on the download page, or shrink wrap packaging of your
software, and offer to download and/or install the latest version for them.
You could have your program detect the Java version and refuse to run for
certain values.

- Oliver
 
J

Joe Attardi

Oliver said:
You could have your program detect the Java version and refuse to run for
certain values.
That could cause ugly exceptions depending on (1) the JDK the app was
built on and (2) the JRE the end user is running on.

For example, I believe (this is from memory, so I could be wrong) if an
app built on a Java 5 JDK is run on a JRE 1.4.x VM, an
UnsupportedMajorMinorException is thrown due to the different
serialVersionUID.
 
O

Oliver Wong

Joe Attardi said:
That could cause ugly exceptions depending on (1) the JDK the app was
built on and (2) the JRE the end user is running on.

For example, I believe (this is from memory, so I could be wrong) if an
app built on a Java 5 JDK is run on a JRE 1.4.x VM, an
UnsupportedMajorMinorException is thrown due to the different
serialVersionUID.

So catch those, and show a pop up saying "Please upgrade your JVM". ;)

- Oliver
 
J

Joe Attardi

So catch those, and show a pop up saying "Please upgrade your JVM". ;)
:) Then there's that.

But actually, I think that would be thrown as soon as the main class is
loaded, which I would think would stop any further execution of the
program.
 
A

Alun Harford

Joe Attardi said:
That could cause ugly exceptions depending on (1) the JDK the app was
built on and (2) the JRE the end user is running on.

For example, I believe (this is from memory, so I could be wrong) if an
app built on a Java 5 JDK is run on a JRE 1.4.x VM, an
UnsupportedMajorMinorException is thrown due to the different
serialVersionUID.

You are indeed wrong.

Alun Harford
 
J

Joe Attardi

Joe said:
For example, I believe (this is from memory, so I could be wrong) if an
app built on a Java 5 JDK is run on a JRE 1.4.x VM, an
UnsupportedMajorMinorException is thrown due to the different
serialVersionUID.

Correction:
I was mixing up class version with serialVersionUID. The actual
exception that would be thrown is UnsupportedClassVersionError, with a
message stating "Unsupported major.minor version 49.0".

This would be thrown _as soon_ as the main class is loaded, before
main() gets executed. So detecting older JREs programmatically would
_not_ work...
 
L

lewmania942

Hi,

Joe said:
For example, I believe (this is from memory, so I could be wrong) if an
app built on a Java 5 JDK is run on a JRE 1.4.x VM, an
UnsupportedMajorMinorException is thrown due to the different
serialVersionUID.

You're thinking of UnsupportedClassVersionError (Unsupported
major.minor version xx.x). Note however that you can "-target",
say, an 1.4 JVM using an 1.5 compiler.

Here's an example of the exception you're thinking of:

....$ java -jar /home/example/fakejar42.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/fake/FakeJar (Unsupported major.minor version 49.0)

The serialVersionUID isn't related to this however (which may be
what Alun Harford was referring to but it's not clear from his
very verbose and very informative post ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top