[OFBiz] Dev - start up check for JRE version compatibility

bjfree at free-man.net bjfree at free-man.net
Sun Aug 1 12:22:12 EDT 2004


ran across this code, thought it might help.  I have added version above 1.3
it check for routines in each version what was not in the previous.
this way if someone has a version above or below the current supported
version, at least ofbiz can warn them.

Also this neat sight lets you look up for newer versions as they are
released.
http://javadiff.sourceforge.net/


code:

public class Versions {

	/**
	 * 
	 */
	  public static final String JAVA_1_0 = "1.0";
	  public static final String JAVA_1_1 = "1.1";
	  public static final String JAVA_1_2 = "1.2";
	  public static final String JAVA_1_3 = "1.3";
	  public static final String JAVA_1_4 = "1.4.2";
	  public static final String JAVA_1_5 = "1.5.0b1";
	  public static final String JAVA_UNKOWN = "Unknown";
	  private static String javaVersion;
	  private String GetJavaVersion()
	  {
	    // Determine the Java version by looking at available classes
	    // java.lang.StrictMath was introduced in JDK 1.3
	    // java.lang.ThreadLocal was introduced in JDK 1.2
	    // java.lang.Void was introduced in JDK 1.1
	    // Count up version until a NoClassDefFoundError ends the try
	    try {
	      javaVersion = JAVA_1_0;
	      Class.forName( "java.lang.Void" );
	      javaVersion = JAVA_1_1;
	      Class.forName( "java.lang.ThreadLocal" );
	      javaVersion = JAVA_1_2;
	      Class.forName( "java.lang.StrictMath" );
	      javaVersion = JAVA_1_3;
	      Class.forName( "java.util.regex" );
	      javaVersion = JAVA_1_4;
	      Class.forName( "java.util.concurrent" );
	      javaVersion = JAVA_1_5;
	   }
	    catch ( ClassNotFoundException cnfe ) {
	      // swallow as we've hit the max class version that
	      // we have
	    	javaVersion = JAVA_UNKOWN;
	    }

	    // sanity check
	    if ( javaVersion == JAVA_1_0 ) {
	      throw new Exception( "Ant cannot work on Java 1.0" );
	    }

	    log( "Detected Java Version: " + javaVersion );

	    log( "Detected OS: " + System.getProperty( "os.name" ));
	  }

	 
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe at ofbiz.dev.java.net
For additional commands, e-mail: dev-help at ofbiz.dev.java.net






More information about the Dev mailing list