Saturday, September 06, 2008

Java 1.6 and wsimport on Mac OS X Leopard 10.5.4

If you are a java developer and a Mac OS X Leopard user, it might be the case that you've been wondering why you apparently only have Java JVM 1.5 available on your computer. If you open a terminal and check for the java version, you get the following:

> java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)

However, you'll see there are many more JVM versions installed in Mac OS X, using the frameworks directory structure which is excellent to my opinion. See how you can use java 1.3 to 1.6 in a standard Leopard install:

> cd /System/Library/Frameworks/JavaVM.framework/Versions/
> ls
1.3 1.3.1 1.4 1.4.1 1.4.2 1.5 1.5.0 1.6 1.6.0 A Current CurrentJDK

So you can easily get to Java 1.6:

> cd /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/
> ./java -version
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13-120)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_05-b13-52, mixed mode)
I use wsimport in order to generate java classes for a web service client (or JAX-WS portable artifacts, if you prefer the official definition). This tool is available from Java 1.6. However, if you try to run wsimport on Leopard you'll get frustrated:
> ./wsimport
Exception in thread "main" java.lang.NullPointerException
at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:96)
at com.sun.tools.internal.ws.WsImport.main(WsImport.java:38)

This is a bug that has already been discussed in apple developer mailing lists (here and here).

The best solution I found is simply installing the latest version of JAX-WS from the Glassfish website. Just double click on the downloaded jar file, and after accepting the licence agreement it will expand files into folders named jaxb-ri and jaxws-ri. You can then enter the jaxws-ri folder and run wsimport from there:
> cd jaxws-ri/bin
./wsimport.sh
Missing WSDL_URI

Usage: wsimport [options]
(...)
I hope that helps :)

1 comment:

  1. Thanks! I was really thrown when I saw that my new Leopard installation was using 1.5. Glad 1.6 was just hiding.

    ReplyDelete