01: /*
02: * Enhydra Java Application Server Project
03: *
04: * The contents of this file are subject to the Enhydra Public License
05: * Version 1.1 (the "License"); you may not use this file except in
06: * compliance with the License. You may obtain a copy of the License on
07: * the Enhydra web site ( http://www.enhydra.org/ ).
08: *
09: * Software distributed under the License is distributed on an "AS IS"
10: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11: * the License for the specific terms governing rights and limitations
12: * under the License.
13: *
14: * The Initial Developer of the Enhydra Application Server is Lutris
15: * Technologies, Inc. The Enhydra Application Server and portions created
16: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17: * All Rights Reserved.
18: *
19: * Contributor(s):
20: *
21: * $Id: JavaVersion.java,v 1.2 2006-06-15 13:47:01 sinisa Exp $
22: */
23:
24: package com.lutris.util;
25:
26: /*
27: * JavaVersion can be used as a standalone main class
28: * to print the major version number of the executing JVM
29: * or it can return the version using the getVersion() method.
30: *
31: * @version $Revision: 1.2 $
32: * @author Shawn McMurdo
33: * @author Jason Hunter (jhunter@hyperreal.org)
34: */
35: public class JavaVersion {
36:
37: static {
38: setVersion();
39: }
40: public static String javaVersion;
41:
42: public static void main(String argv[]) {
43: System.out.println(javaVersion);
44: }
45:
46: public static String getVersion() {
47: return javaVersion;
48: }
49:
50: private static void setVersion() {
51: // From Jason Hunter via Jakarta Tomcat
52: // This method includes software developed by the
53: // Apache Software Foundation <http://www.apache.org/>.
54:
55: // Determine the Java version by looking at available classes
56: // java.lang.StrictMath was introduced in JDK 1.3
57: // java.lang.ThreadLocal was introduced in JDK 1.2
58: // java.lang.Void was introduced in JDK 1.1
59: // Count up version until a NoClassDefFoundError ends the try
60: try {
61: javaVersion = "1.0";
62: Class.forName("java.lang.Void");
63: javaVersion = "1.1";
64: Class.forName("java.lang.ThreadLocal");
65: javaVersion = "1.2";
66: Class.forName("java.lang.StrictMath");
67: javaVersion = "1.3";
68: } catch (Throwable t) {
69: }
70: }
71: }
|