users@jaxb.java.net

Re: JDK 1.6, Ant and JAXB 2.1 Commons plugins: ClassCastException from com.sun.tools.xjc.Options.findServices

From: Rama Pulavarthi <Rama.Pulavarthi_at_Sun.COM>
Date: Tue, 10 Mar 2009 10:55:52 -0700

Hi Andreas,
Andreas Loew wrote:
> Hi Aleksei, hi all,
>
> unfortunately, it looks like even after integration of JAXB 2.1 API
> into JDK 1.6.0_04, there still seem to be some classloading issues
> stopping me from using the JAXB2 Commons plugins running on JDK 1.6 in
> an Ant-based scenario:
>
I don't think JDK 1.6.0_04 is the reason for this problem. JDK 1.6.0_04
already has JAXB 2.1 API and if your standalone JAXB impl is in the
classpath, you don't need to use endorsed mechansim with JDK 6u4.
Standalone JAXB RI is tested to work with latest JDK 6 update releases.

How are you defining your wsimport ant task in your project? Are you
using fork option for wsimport?

thanks,
Rama Pulavarthi
> I am using an Ant-based and wizard-generated project from within
> NetBeans 6.1 using Glassfish v2.0/Metro 1.1, but after I added the
> JAXB2 equals, hashCode, toString and copyable plugins, I keep getting
> the following exception:
>
> ==============
> init:
> deps-module-jar:
> deps-ear-jar:
> deps-jar:
> wsimport-init:
> Created dir:
> /home/al130959/Projekte/osiris/svn/trunk/tmf615-server/TMF615ServiceEndpoint/build/generated/wsimport/service
>
> Created dir:
> /home/al130959/Projekte/osiris/svn/trunk/tmf615-server/TMF615ServiceEndpoint/build/generated/wsimport/binaries
>
> wsimport-service-check-TMF615Service:
> wsimport-service-TMF615Service:
> Consider using <depends>/<produces> so that wsimport won't do
> unnecessary compilation
> command line: wsimport -d
> /home/al130959/Projekte/osiris/svn/trunk/tmf615-server/TMF615ServiceEndpoint/build/generated/wsimport/binaries
> -extension -keep -s
> /home/al130959/Projekte/osiris/svn/trunk/tmf615-server/TMF615ServiceEndpoint/build/generated/wsimport/service
> -catalog
> /home/al130959/Projekte/osiris/svn/trunk/tmf615-server/TMF615ServiceEndpoint/catalog.xml
> -verbose
> /home/al130959/Projekte/osiris/svn/trunk/tmf615-server/TMF615ServiceEndpoint/src/conf/xml-resources/web-services/TMF615Service/wsdl/TMF615_spmlv2_um_service.wsdl
> -B-Xequals -B-XhashCode -B-XtoString -B-Xcopyable
> java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin:
> Provider org.jvnet.jaxb2_commons.plugin.jaxbindex.JaxbIndexPlugin
> could not be instantiated: java.lang.ClassCastException
> at java.util.ServiceLoader.fail(ServiceLoader.java:207)
> at java.util.ServiceLoader.access$100(ServiceLoader.java:164)
> at
> java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:353)
> at java.util.ServiceLoader$1.next(ServiceLoader.java:421)
> at com.sun.tools.xjc.Options.findServices(Options.java:884)
> at com.sun.tools.xjc.Options.getAllPlugins(Options.java:336)
> at com.sun.tools.xjc.Options.parseArgument(Options.java:632)
> at
> com.sun.tools.ws.wscompile.WsimportOptions.parseArguments(WsimportOptions.java:190)
>
> at
> com.sun.tools.ws.wscompile.Options.parseArguments(Options.java:229)
> at
> com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:166)
> at com.sun.tools.ws.ant.WsImport2.execute(WsImport2.java:665)
> at
> com.sun.istack.tools.ProtectedTask.execute(ProtectedTask.java:55)
> at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
> at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>
> at org.apache.tools.ant.Task.perform(Task.java:348)
> at org.apache.tools.ant.Target.execute(Target.java:357)
> at org.apache.tools.ant.Target.performTasks(Target.java:385)
> at
> org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
> at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
> at
> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>
> at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
> at
> org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:277)
>
> at
> org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:460)
>
> at
> org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)
> Caused by: java.lang.ClassCastException
> at java.lang.Class.cast(Class.java:2990)
> at
> java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:345)
> ... 24 more
> BUILD FAILED (total time: 0 seconds)
> ==============
>
> I ran across the following old mail:
>
> ==============
> Date: Wed, 16 Jan 2008 10:02:12 +0100
> From: Aleksei Valikov <valikov_at_gmx.net>
> Subject: hyperjax3 + ant = ClassCastException
>
> (...)
>
> It's a known problem with Ant/Java 1.6/JAXB 2.1. JAXB 2.1 plugins
> don't work in this constellation and there's not much to do about it.
>
> To resolve, try:
>
> 1. Add JAXB 2.1 API to your endorsed dir (probably won't help).
> 2. Build with Java 1.5.
> 3. Build with Maven (works fine on both Java 1.5 and Java 1.6).
> 4. Wait till JAXB 2.1 will be integrated into JDK (rumors that it'll
> happen in Java 6 update 4).
> 5. Wait till I'll write a better XJC task.
> ==============
>
> So I tried some of the steps above with the following outcome:
>
> 1. Does not work. Still the exact same result (as you correctly assumed).
> 2. Does work fine, but as Ant is run from within the JVM that started
> NetBeans, this would force me to run NetBeans on JDK 1.5, which simply
> looks horrible on Linux (no GTK LAF)...
> 3. Migrating to Maven is not an option for this my current project
> right now... :-(
> 4. The issue is the same with all 1.6.0 JDKs, regardless of whether <
> 1.6.0_04 or >= 1.6.0_04. I even tried with 1.6.0_14-ea, but without
> luck...
>
> Therefore, my question now is:
>
> Is there any chance that you may find some time for solution 5. ("I'll
> write a better XJC task") or at least provide some pointers to what
> exactly goes wrong and would have to be changed?
>
> Many thanks in advance for your kind help!
>
> Best regards,
>
> Andreas
>