Fixing CXF java.lang.IllegalStateException: Unable to create JAXBContext for generated packages

Our CXF client-server tests passed in Eclispe (3.6M6) but failed when invoked from the command line with Ant 1.7.1. This stack trace is a typical example:

java.lang.IllegalStateException: Unable to create JAXBContext for generated packages: "appinterface.seagullsw.com.appinterfaceserver" doesnt contain ObjectFactory.class or jaxb.index
  at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:343)
  at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:196)
  at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:175)
  at com.seagullsw.appinterface.server.comm.soap.SoapCmCxfTests.testWssAll(SoapCmCxfTests.java:354)
Caused by: javax.xml.bind.JAXBException: "appinterface.seagullsw.com.appinterfaceserver" doesnt contain ObjectFactory.class or jaxb.index
  at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)
  at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
  at javax.xml.bind.ContextFinder.find(ContextFinder.java:277)
  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
  at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:340)

We use CXF 2.2.7 and JAXB 2.2 but this also applies for older versions of CXF and JAXB.

The solution is to add the JDK bin directory to your execution path (PATH on Windows), something like:

set PATH=%PATH%;%JAVA_HOME%\bin

where JAVA_HOME points to your JDK root directory.

Now all tests pass from Eclipse and Ant.

2 thoughts on “Fixing CXF java.lang.IllegalStateException: Unable to create JAXBContext for generated packages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s