Snow Leopard, Java 6 and GWT

September 2nd, 2009 Alex Moffat Posted in GWT, Java | 23 Comments »

So, as we all know, GWT hosted mode on the Mac with OS X Leopard didn’t work with Java 6 because Java 6 on the Mac was 64 bit only and the libraries used for hosted mode were 32 bit. You’d get java.lang.UnsatisfiedLinkError. The workaround was to use Java 5 for hosted mode. The release of Snow Leopard put paid to this scheme. In Snow Leopard you only have Java 6. A look at the installed Java versions shows 1.5 has been replaced by a link to CurrentJDK and CurrentJDK is 1.6.

  googleio_2009 $ ls -l /System/Library/Frameworks/JavaVM.framework/Versions
  total 48
  lrwxr-xr-x  1 root  wheel    5 Sep  1 10:56 1.3 -> 1.3.1
  drwxr-xr-x  3 root  wheel  102 Jul 20 18:35 1.3.1
  lrwxr-xr-x  1 root  wheel   10 Sep  1 10:56 1.5 -> CurrentJDK
  lrwxr-xr-x  1 root  wheel   10 Sep  1 10:56 1.5.0 -> CurrentJDK
  lrwxr-xr-x  1 root  wheel    5 Sep  1 10:56 1.6 -> 1.6.0
  drwxr-xr-x  8 root  wheel  272 Sep  1 11:20 1.6.0
  drwxr-xr-x  9 root  wheel  306 Sep  1 11:20 A
  lrwxr-xr-x  1 root  wheel    1 Sep  1 10:56 Current -> A
  lrwxr-xr-x  1 root  wheel    3 Sep  1 10:56 CurrentJDK -> 1.6
  googleio_2009 $

However, Java 6 on the Mac now has an option to run in 32 bit mode. Here’s the first few lines of the help info for the Java executable.

  googleio_2009 $ java -help
  Usage: java [-options] class [args...]
             (to execute a class)
     or  java [-options] -jar jarfile [args...]
             (to execute a jar file)

  where options include:
      -d32          use a 32-bit data model if available
      -d64          use a 64-bit data model if available (implies -server, only for x86_64)

So it should be possible to run “java -d32″ instead of “java” and have it all work.

No such luck. You get the message “You must use a Java 1.5 runtime to use GWT Hosted Mode on Mac OS X.”

This is issued by the BootStrapPlatform class which is in gwt-dev-mac.jar. One of the great things about GWT when you’re looking at issues like this, which happens very infrequently, is that the source code is so easily available, it’s in the same jar file. The lines of code involved are in the initHostedMode method

  if (!isJava5()) {
      System.err.println("You must use a Java 1.5 runtime to use GWT Hosted Mode on Mac OS X.");
      System.exit(-1);
    }

and the isJava5 method is very simple

  private static boolean isJava5() {
    return System.getProperty("java.version").startsWith("1.5");
  }

My work around, till we get out of process hosted mode, is very simple. Copy source for the BootStrapPlatform class into my project and modify the isJava5 method to always return true. For hosted mode I arrange the classpath to have my source and class directories in front of the GWT jar files so the modified version is picked up instead of the GWT supplied one.

Now it’s possible to use “java -d32″ and everything works fine, hosted mode running with Java 6, hurray! At Lombardi we have Mac, Windows and Linux uses so I’ll have to put together some system that only replaces the BootStrapPlatform for Mac users but that’s not going to be too hard.

23 Responses to “Snow Leopard, Java 6 and GWT”

  1. Good stuff. I was getting ready to look into this when I saw your post.

  2. Another solution is to replace the link from 1.5 to 1.6 with a saved copy of the Leopard 1.5 JDK. In the Eclipse run configuration for hosted mode you have to explicitly set 1.5 as used JRE.

  3. Before Snow Leopard was released this was what I was doing, using 1.5 for hosted mode and 1.6 for the back end code. Now that only 1.6 is available I wanted to see if I could use it instead. On Windows we had a similar issue with 32 bit vs 64 bit jvms, we run 64 bit in production for increased memory use but couldn’t use that for hosted mode debugging. Our build scripts use two environment settings JAVA_HOME and JAVA_EXEC_32 so that the we have definitions for the two jdks we need.

  4. [...] gegeben. Zusammenfassend gebe ich hier mal eine kleine Anleitung die auf einem Blogeintrag im Lombardi Development Blog basiert. Das Schöne ist, dass kein Nachinstallieren von Java 5 nötig [...]

  5. How do you recompile the whole thing before packagint it into a jar?

  6. I don’t bother. I just put it in a normal classes directory and put that in front of the gwt-dev-mac.jar file on the class path. An easy alternative is to unjar the gwt-dev-mac.jar file, replace the BootStrapPlatform.class file with the modified version and then rejar to recreate the gwt-dev-mac.jar file. I prefer the first (slightly) because it reminds me that I’ve made modifications in case I have to reapply them to later versions.

  7. Eelco Hillenius Says:

    Awesome, thanks!

    When I’m putting this class in my regular source dir in my project in Eclipse, the compiler complains about AWT not being supported (in the initGui method), but jar-ing the class and add it to the projects class path solves that.

  8. I’ve packaged a new jar and replace the current gwt-dev-mac.jar.
    Just put “-d32″ as default VM Arguments in my default eclipse installed JVM to avoid “corrupted GWT Installation” message. And all my GWT projects works now with minimal efforts !

    Thanks for this tip Alex!

  9. This is a great post. Thanks for posting. However I do want to send a bit of a religious message…the fact that Snow Leopard was going to be 64 bit Java was not exactly a secret and I think we, as a community should put more pressure on people like Google to ensure their offerings are ready for things like Snow Leopard. The workaround on their end would be fairly minimal if you think about it, and they could easily offer a simple patch to get this done without the community searching for a solution. Especially since Java 5 is nearing end of service life you’d think products like GWT would have better support for Java 6.

    Just my $0.02. Not to take away from a great post on a perfectly legitimate fix while waiting for something from Google.

  10. [...] Lombardi Development Blog » Blog Archive » Snow Leopard, Java 6 and GWT. [...]

  11. This is excellent ! Very happy to see an elegant workaround. It took me 2 minutes…and I was back in business.

    I was considering the fix with JAVA 1.5 from leopard and hack the links in the System/Library, but I do not want to go there…

    Thank you very much !

  12. This worked for me to. I copied the 1.7.0 binary to my mobile me account, so you can grab it from http://files.me.com/armhold/k5f4tn if you don’t want to build it yourself. Enjoy.

  13. @MiKey I agree. I was a bit surprised that there wasn’t at least some notice on the GWT web site. Mac users tend to be pretty crazy about upgrading as soon as a new version is out and it’s a shame when something as important to us as GWT is doesn’t work. On the other hand, hurray for release of the source code so that the hack could be made.

  14. “I arrange the classpath to have my source and class directories in front of the GWT jar files so the modified version is picked up instead of the GWT supplied one.”

    I’ve jared the BootStrapPlatform file with the correction but i do not know how to configure my classpath correctly, a little example ?

  15. I don’t modify the delivered jar, instead the script I use to execute hosted mode includes

    -cp “${SRC_PATH}:${OVERRIDE}:${GWT_HOME}/gwt-dev-mac.jar:${GWT_HOME}/gwt-user.jar”

    to set the classpath where SRC_PATH is the path to the source code, OVERRIDE is the path to where the BootStrapPlatform class is. In my case OVERRIDE is target/gwtoverride and when I compile my modified BootStrapPlatform class that’s where it goes. So BootStrapPalatform should be picked up from there in preference to the gwt-dev-mac.jar.

    If you’re not getting the effect you expect the easiest thing to do is to put a System.out.println statement in the isJava5 method to make sure the right class is getting called.

  16. Instructions to put back the old Java 5 and Java 4 Leopard versions:

    http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard

    This page mentions the use of “wget”. I have “wget” installed via MacPorts but, obviously, you can just download the archives (if you want to use those) directly via Safari.

  17. I wanted to ensure I didn’t forget the ‘-d32′ switch, so I replaced isJava5() with is64bit():


    public static void initHostedMode() {
    /*
    * The following check must be made before attempting to initialize Safari,
    * or we’ll fail with an less-than-helpful UnsatisfiedLinkError.
    */
    if (is64bit()) {
    System.err.println(”You must use a 32-bit Java runtime to use GWT Hosted Mode on Mac OS X.”);
    System.exit(-1);
    }

    /**
    * Determine if we’re using a 64bit runtime
    */
    private static boolean is64bit() {
    return System.getProperty(”java.vm.name”).contains(”64-Bit”);
    }

  18. @JimTomlinson That’s a nicer approach. The message is much more helpful.

  19. [...] want to give the credits of this Idea (sure is not all mine) to Lombardi and Bizo eclipse, GWT, Mac, Tips Name Email Website [...]

  20. [...] for a 32-bit runtime by Google. Luckily there is a way to work around this problem. The Lombardi blog has an entry explaining the reasons and what needs to be [...]

  21. Great information re: GWT 1.7.

    Just tonight I noticed in Eclipse it said there was GWT updates so installed them and GWT 1.7.1 installed. I went in to edit it with these changes but the error message was not present. So, I switched my project over to using the new GWT version (1.7.1) and hosted mode fired up without an error.

  22. You may enjoy the GWT 2.0 preview which can be found here: http://code.google.com/p/google-web-toolkit/downloads/list?can=4&q=2.0

    It has a “development” mode which runs right on top of firefox. (The chrome plugin causes the developer’s version for the mac to crash as of this writing.)

  23. I’m looking forward to GWT 2.0. Out of process hosted mode will be great, I hope :) .

Leave a Reply