Skip to main content

Yet another JAXB compatability issue

2 replies [Last post]
Anonymous

Hello Metro community,

I'm running into what seems as some compatibility issues while migrating a
legacy application to a new platform - Java SE 7, Java EE 6, JBoss AS 7.1.1.
JBoss AS 7.1.1 provides CXF 2.4.6. Using Maven and cxf-codegen-plugin:2.4.6
code gets generated from wsdl file.

Unfortunately tests which reference generated code fail with:

foo.Bar$JaxbAccessorF_aField cannot be cast to
com.sun.xml.internal.bind.v2.runtime.reflect.Accessor

Does anyone know what could be the problem here and how to fix it?

Please correct me if wrong, but it seems to me this is caused by some
compatibility issue, more specifically JAXB versions, one version used to
generate code and other at (test) runtime.
I'm using Java SE 7 to run tests (and maven 3.0.4). If I'm not mistaken,
Java SE 7 update 5 embeds JAXB 2.2.4, and JAXB 2.2 is part of Java EE 6
provided APIs and JBoss 7.1.1 provides appropriate implementation.

I guess internal part in
com.sun.xml.internal.bind.v2.runtime.reflect.Accessor suggests that
something is using Java SE internal/embedded JAXB, while something else is
using non-internal variant or different incompatible version.
Not sure who is using what but I assume cxf-codegen-plugin:2.4.6 is using
non-internal JAXB 2.2.
I've tried to configure endorsing jaxb-impl, jaxb-api and jaxb-xjc in both
maven-compiler-plugin, and maven-surefire-plugin (use
maven-dependency-plugin to copy these libs in target/endorsed, and then in
compiler and tests configure this as endorsed directory) but I'm still
getting same error.
Then I found this post
http://jaxb.java.net/guide/Migrating_JAXB_2_0_applications_to_JavaSE_6.h...
even after configuring maven to endorse only jaxb-api, same
ClassCastException gets thrown.

Any constructive ideas are welcome. Thanks in advance!

Kind regards,
Stevo Slavić.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
snajper
Offline
Joined: 2004-10-01
Points: 0

Yes it appears like there's a clash of 2 implementations - one from JDK
(*internal* packages), one standalone. You should double check that you
don't mix the 2 at once. When doing the endorsed dir magic, make sure
that *only* jaxb-api jar is in endorsed dir. All other jaxb jars should
be on classpath, but not in the endorsed directory,
MartiNG

On 6/29/12 10:08 AM, Stevo Slavić wrote:
> Hello Metro community,
>
> I'm running into what seems as some compatibility issues while
> migrating a legacy application to a new platform - Java SE 7, Java EE
> 6, JBoss AS 7.1.1.
> JBoss AS 7.1.1 provides CXF 2.4.6. Using Maven and
> cxf-codegen-plugin:2.4.6 code gets generated from wsdl file.
>
> Unfortunately tests which reference generated code fail with:
>
> foo.Bar$JaxbAccessorF_aField cannot be cast to
> com.sun.xml.internal.bind.v2.runtime.reflect.Accessor
>
> Does anyone know what could be the problem here and how to fix it?
>
> Please correct me if wrong, but it seems to me this is caused by some
> compatibility issue, more specifically JAXB versions, one version used
> to generate code and other at (test) runtime.
> I'm using Java SE 7 to run tests (and maven 3.0.4). If I'm not
> mistaken, Java SE 7 update 5 embeds JAXB 2.2.4, and JAXB 2.2 is part
> of Java EE 6 provided APIs and JBoss 7.1.1 provides appropriate
> implementation.
>
> I guess internal part in
> com.sun.xml.internal.bind.v2.runtime.reflect.Accessor suggests that
> something is using Java SE internal/embedded JAXB, while something
> else is using non-internal variant or different incompatible version.
> Not sure who is using what but I assume cxf-codegen-plugin:2.4.6 is
> using non-internal JAXB 2.2.
> I've tried to configure endorsing jaxb-impl, jaxb-api and jaxb-xjc in
> both maven-compiler-plugin, and maven-surefire-plugin (use
> maven-dependency-plugin to copy these libs in target/endorsed, and
> then in compiler and tests configure this as endorsed directory) but
> I'm still getting same error.
> Then I found this post
> http://jaxb.java.net/guide/Migrating_JAXB_2_0_applications_to_JavaSE_6.html
> but even after configuring maven to endorse only jaxb-api, same
> ClassCastException gets thrown.
>
> Any constructive ideas are welcome. Thanks in advance!
>
> Kind regards,
> Stevo Slavić.

=?UTF-8?Q?Stevo_Slavi=C4=87?=

I already had JAXB API endorsed well. It was JAX-WS API, needed to endorse
that one too.

Thanks for support!

Kind regards,
Stevo Slavić.

On Fri, Jun 29, 2012 at 10:19 AM, Martin Grebac wrote:

> Yes it appears like there's a clash of 2 implementations - one from JDK
> (*internal* packages), one standalone. You should double check that you
> don't mix the 2 at once. When doing the endorsed dir magic, make sure that
> *only* jaxb-api jar is in endorsed dir. All other jaxb jars should be on
> classpath, but not in the endorsed directory,
> MartiNG
>
>
> On 6/29/12 10:08 AM, Stevo Slavić wrote:
>
>> Hello Metro community,
>>
>> I'm running into what seems as some compatibility issues while migrating
>> a legacy application to a new platform - Java SE 7, Java EE 6, JBoss AS
>> 7.1.1.
>> JBoss AS 7.1.1 provides CXF 2.4.6. Using Maven and
>> cxf-codegen-plugin:2.4.6 code gets generated from wsdl file.
>>
>> Unfortunately tests which reference generated code fail with:
>>
>> foo.Bar$JaxbAccessorF_aField cannot be cast to
>> com.sun.xml.internal.bind.v2.**runtime.reflect.Accessor
>>
>> Does anyone know what could be the problem here and how to fix it?
>>
>> Please correct me if wrong, but it seems to me this is caused by some
>> compatibility issue, more specifically JAXB versions, one version used to
>> generate code and other at (test) runtime.
>> I'm using Java SE 7 to run tests (and maven 3.0.4). If I'm not mistaken,
>> Java SE 7 update 5 embeds JAXB 2.2.4, and JAXB 2.2 is part of Java EE 6
>> provided APIs and JBoss 7.1.1 provides appropriate implementation.
>>
>> I guess internal part in com.sun.xml.internal.bind.v2.**runtime.reflect.Accessor
>> suggests that something is using Java SE internal/embedded JAXB, while
>> something else is using non-internal variant or different incompatible
>> version.
>> Not sure who is using what but I assume cxf-codegen-plugin:2.4.6 is using
>> non-internal JAXB 2.2.
>> I've tried to configure endorsing jaxb-impl, jaxb-api and jaxb-xjc in
>> both maven-compiler-plugin, and maven-surefire-plugin (use
>> maven-dependency-plugin to copy these libs in target/endorsed, and then in
>> compiler and tests configure this as endorsed directory) but I'm still
>> getting same error.
>> Then I found this post http://jaxb.java.net/guide/**Migrating_JAXB_2_0_**
>> applications_to_JavaSE_6.htmlbut even after configuring maven to endorse only jaxb-api, same
>> ClassCastException gets thrown.
>>
>> Any constructive ideas are welcome. Thanks in advance!
>>
>> Kind regards,
>> Stevo Slavić.
>>
>