detecting which jvm version is being ran?  
Author Message
yawnmoth





PostPosted: 2006-11-21 2:27:00 Top

java-programmer, detecting which jvm version is being ran? 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?

 
saotome





PostPosted: 2006-11-21 2:41:00 Top

java-programmer >> detecting which jvm version is being ran? 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()

On Nov 20, 2:27 pm, "yawnmoth" <email***@***.com> wrote:
> 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?

 
yawnmoth





PostPosted: 2006-11-21 5:32:00 Top

java-programmer >> detecting which jvm version is being ran?
saotome wrote:
> 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).

 
 
Andrew Thompson





PostPosted: 2006-11-21 5:57:00 Top

java-programmer >> detecting which jvm version is being ran? yawnmoth wrote:
> saotome wrote:
> > 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?

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.

 
 
Eric Sosman





PostPosted: 2006-11-21 6:02:00 Top

java-programmer >> detecting which jvm version is being ran?

yawnmoth wrote On 11/20/06 16:32,:
> saotome wrote:
>
>>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).

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.

--
email***@***.com

 
 
Andrew Thompson





PostPosted: 2006-11-21 7:39:00 Top

java-programmer >> detecting which jvm version is being ran? Eric Sosman wrote:
...
> Try (and I say "try" because I haven't tried it myself)
>
> String javaversion = System.getProperty("java.version");

..or try it here..
<http://www.physci.org/pc/jtest-applet.jnlp>

That (sandboxed) applet indicates some of the properties
that are allowed and blocked, for an untrusted applet..

Andrew T.

 
 
Arne Vajh鴍





PostPosted: 2006-11-21 9:10:00 Top

java-programmer >> detecting which jvm version is being ran? yawnmoth wrote:
> saotome wrote:
>> 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).

Try:

http://www.vajhoej.dk/arne/eksperten/showversion/showversion.html

The source are at:

http://www.vajhoej.dk/arne/eksperten/showversion/ShowVersion.java

Arne
 
 
Mickey Segal





PostPosted: 2006-11-21 11:21:00 Top

java-programmer >> detecting which jvm version is being ran? "Andrew Thompson" <email***@***.com> wrote in message
news:email***@***.com...
> <http://www.physci.org/pc/jtest-applet.jnlp>

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.


 
 
yawnmoth





PostPosted: 2006-11-29 2:57:00 Top

java-programmer >> detecting which jvm version is being ran? Mickey Segal wrote:
> "Andrew Thompson" <email***@***.com> wrote in message
> news:email***@***.com...
> > <http://www.physci.org/pc/jtest-applet.jnlp>
>
> 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鴍 posted?

 
 
Andrew Thompson





PostPosted: 2006-11-29 5:53:00 Top

java-programmer >> detecting which jvm version is being ran? yawnmoth wrote:
> 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鴍 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.

 
 
yawnmoth





PostPosted: 2006-12-8 4:18:00 Top

java-programmer >> detecting which jvm version is being ran?
Andrew Thompson wrote:
> yawnmoth wrote:
> > 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.
Sorry for the delay - the person who had their browser crash never
replied to my requests for more information.

Anyway, here's the URL:

http://www.geocities.com/terra1024/showInfo.html

The source of ShowInfo.class is here:

http://www.geocities.com/terra1024/ShowInfo.java

 
 
Andrew Thompson





PostPosted: 2006-12-8 8:54:00 Top

java-programmer >> detecting which jvm version is being ran? yawnmoth wrote:
> Andrew Thompson wrote:
> > yawnmoth wrote:
> > > 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)
..
> http://www.geocities.com/terra1024/showInfo.html

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.

Andrew T.

 
 
Mickey Segal





PostPosted: 2006-12-8 9:48:00 Top

java-programmer >> detecting which jvm version is being ran? "Andrew Thompson" <email***@***.com> wrote in message
news:email***@***.com...
> 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.


 
 
Andrew Thompson





PostPosted: 2006-12-8 10:19:00 Top

java-programmer >> detecting which jvm version is being ran? yawnmoth wrote:
...
> Anyway, here's the URL:
>
> http://www.geocities.com/terra1024/showInfo.html

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%3A%2F%2Fwww.physci.org%2Ftest%2Fapplet%2F002%2F>

Andrew T.