detecting which jvm version is being ran?

Y

yawnmoth

Say I have an applet and would like to display which version of the JVM
is being used from the applet. Any ideas as to how to do this?
 
Y

yawnmoth

saotome said:
Make a call to System.getProperties(). That will return a properties
object that contains information about your environment. The
'java.version' key will return a value with what you are looking for.
This also has other information that may be useful for your needs. For
further information check out:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#getProperties()
This doesn't seem to be possible when done via applets?

I say that because when I tried to run it via an applet, I got this
error message:

exception: java.security.AccessControlException: access denied
(java.util.PropertyPermission * read,write).
 
A

Andrew Thompson

yawnmoth said:
This doesn't seem to be possible when done via applets?

Sure it is, if the applet is signed and trusted.

Finding all the properties that are defined could
be a security risk, so an untrusted applet will only
ever allow certain information to be obtained,
and will not give the 'full list' of properties defined.
I say that because when I tried to run it via an applet, I got this
error message:

exception: java.security.AccessControlException: access denied
(java.util.PropertyPermission * read,write).

Try calling for each property of interest separately,
in this case..
System.getProperty("java.version");

Note it might be handy to run the 'getProperties()'
from the command line to find out the typical property
names.

Andrew T.
 
E

Eric Sosman

yawnmoth wrote On 11/20/06 16:32,:
This doesn't seem to be possible when done via applets?

I say that because when I tried to run it via an applet, I got this
error message:

exception: java.security.AccessControlException: access denied
(java.util.PropertyPermission * read,write).

Try (and I say "try" because I haven't tried it myself)

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

The security manager may be willing to let you read a subset
of the properties but not all of them.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

M

Mickey Segal

Andrew Thompson said:

At www.segal.org/java/config/ we use the following code to get the maximal
information about the Java version:

if ((System.getProperty("java.vendor").startsWith("Microsoft")))
javaVersion = "java.version = " +
System.getProperty("java.version");
else javaVersion = "java.vm.version = " +
System.getProperty("java.vm.version");

The applet is unsigned and it works without security messages in any
environment that I've checked.
 
Y

yawnmoth

Mickey said:
At www.segal.org/java/config/ we use the following code to get the maximal
information about the Java version:

if ((System.getProperty("java.vendor").startsWith("Microsoft")))
javaVersion = "java.version = " +
System.getProperty("java.version");
else javaVersion = "java.vm.version = " +
System.getProperty("java.vm.version");

The applet is unsigned and it works without security messages in any
environment that I've checked.
I'm using a technique similar to this, now, and am being told by
someone that it crashes their browser.

Here's my code:

import java.applet.*;
import java.awt.*;

public class ShowInfo extends Applet
{
String output = "", javaVendor, javaVersion;

public void start() {
try {
javaVendor = System.getProperty("java.vendor");
javaVersion = javaVendor.startsWith("Microsoft") ?
System.getProperty("java.version") :
System.getProperty("java.vm.version");
} catch (Exception e) {
//e.printStackTrace();
}
}

public void paint(Graphics g) {
g.drawString(javaVendor,10,25);
g.drawString(javaVersion,10,50);
}
}

I tried it, myself, on IE6 with MSJVM 1.1 and FF2 with Sun JVM 1.5 and
both worked. I don't know what browser their using nor do I know the
JVM vendor / version (that's what this script was supposed to find
out...)

Any ideas? Maybe I should be using something more like what Arne
Vajhøj posted?
 
A

Andrew Thompson

yawnmoth said:
Mickey Segal wrote:
I'm using a technique similar to this, now, and am being told by
someone that it crashes their browser.

URL? (of the applet)
Browser (make and version) that crashed?
Java version (the browser was running) when crashed? ....oh. OK.
Any ideas?

1) Ensure the code is compiled suitable for a Java 1.1 VM.
That involves both specifying a target version when comiling,
and most importantly, compiling against a 1.1 version rt.jar.

2) Provide the URL of the applet so I can check it in a 1.1 VM
(I have two available).
..Maybe I should be using something more like what Arne
Vajhøj posted?

I suspect Arne's suggestion uses much the same
techniques as used by myself and Mickey, though
note that Mickey's version has extra subtlety over either
mine or Arne's (it delves into details of the MSVM itself,
that are unavaiable to the other two).

Andrew T.
 
M

Mickey Segal

Andrew Thompson said:
I just tested it in IE using the Sun (1.5.something) plug-in
and then switched to the MSVM (1.1.4) to test it again.
On both occasions the applet came up in the web page
and showed the versions.

I suspect if your user flushes the cache (of any stray
classes from the old version), everything should be fine.

I remember that there was some problem on Macintosh OS 9 at some point, but
if I remember correctly my code was even safe there.
 
A

Andrew Thompson

yawnmoth wrote:
....

I forgot to check at the time, but ..because that HTML
is being served by GeoCities, the crap they wrap around
it makes it very invalid (though it seems to be still
'well formed' as far as I can tell by looking at it).

I grabbed the class and (a crude rendition* of what I
guess was) the original HTML, and put them here..
<http://www.physci.org/test/applet/002/>

If you can find any person that confirms that the
first URL breaks, but the second works, it can
be put down to 'crappy HTML' confusing the
browser.

(..yes, I realise your client has vanished into
thin air, but if they should ever pop by, ask
them to compare the two, I'd be interested in
hearing any problems with hosting applets off
the free sites..)

* I added a 'title' (because I like page titles), and a
character encoding - to make the validator 100% happy..
<http://validator.w3.org/check?uri=http://www.physci.org/test/applet/002/>

Andrew T.
 

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
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top