Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Apache CXF uses a wrong version of JAXB? #140

Closed
mmatczak opened this issue Dec 10, 2014 · 19 comments
Closed

Apache CXF uses a wrong version of JAXB? #140

mmatczak opened this issue Dec 10, 2014 · 19 comments
Assignees
Milestone

Comments

@mmatczak
Copy link
Member

When starting Tomcat I got: java.lang.NoSuchFieldError: REFLECTION. The reason were incompatible JAXB versions taken by org.apache.cxf / cxf-rt-frontend-jaxws / 3.0.2:
com.sun.xml.bind / jaxb-impl / 2.2.10-b140310.1920
com.sun.xml.bind / jaxb-core / 2.2.10-b140310.1920

However according to http://mvnrepository.com/artifact/org.apache.cxf/cxf-core/3.0.2, org.apache.cxf / cxf-rt-frontend-jaxws / 3.0.2 depends on com.sun.xml.bind / jaxb-* / 2.1.14.

After I excluded the version 2.2.10-b140310.1920 and explicitly added the 2.1.14 one of com.sun.xml.bind / jaxb-*, the problem disappeared.

I am not a Maven expert, did anyone have a similar issue?

@hohwille
Copy link
Member

@mmatczak you did not yet commit/push anything related to this, right?
When I start tomcat within eclipse, I do not get this error. Your fix sounds OK with the exclusion but then this would actually be a bug of the CXF release 3.0.2.

The dependencies to "jaxb-:2.2.10-" come from "cxf-rt-databinding-jaxb:3.0.2".
However, also "cxf-core:3.0.2" refers to the same JAXB version.
The interesting this is actually orginated in the dependency management of the cxf-parent POM:
http://repo1.maven.org/maven2/org/apache/cxf/cxf-parent/3.0.2/cxf-parent-3.0.2.pom
See this comment:

by default, we use jaxb 2.1, but java5 profile will override to 2.2

How exactly did you get this error? With WAR file in local tomcat outside eclipse? Which tomcat version?

@hohwille
Copy link
Member

My Eclipse m2e POM view and Maven Dependencies says that we are using jaxb 2.2.10-....
However, maven on the commandline builds a WAR file with jaxb 2.1.14.
There seems to be a maven bug in this specific scenario.
According to this your observation to fix the problem does not make any sense to me.

@hohwille
Copy link
Member

The comment from CXF pom is also wrong - it is not java5 profile but 1.7 that triggers the 2.2 version:

<profile>
            <id>jdk17</id>
            <activation>
                <jdk>1.7</jdk>
            </activation>
            <properties>
                <cxf.jaxb.version>${cxf.jaxb22.version}</cxf.jaxb.version>
                <cxf.jaxb.impl.version>${cxf.jaxb22.impl.version}</cxf.jaxb.impl.version>
                <cxf.jaxb.xjc.version>${cxf.jaxb22.impl.version}</cxf.jaxb.xjc.version>
                <cxf.jaxb.core.version>${cxf.jaxb22.core.version}</cxf.jaxb.core.version>
            </properties>
...
        </profile>

@sobkowiak
Copy link
Member

It must be a problem with the war packaging. Try this

mvn dependency:copy-dependencies

This command resolves the jaxb dependencies correctly

kso@Inspiron-7720:~/work/projects/oasp/devel/java/oasp4j-sample$ mvn dependency:copy-dependencies | grep jaxb
[INFO] Copying jackson-module-jaxb-annotations-2.4.2.jar to /home/kso/work/projects/oasp/devel/java/oasp4j-sample/oasp4j-example-application/target/dependency/jackson-module-jaxb-annotations-2.4.2.jar
[INFO] Copying jaxb-core-2.2.10-b140310.1920.jar to /home/kso/work/projects/oasp/devel/java/oasp4j-sample/oasp4j-example-application/target/dependency/jaxb-core-2.2.10-b140310.1920.jar
[INFO] Copying cxf-rt-databinding-jaxb-3.0.2.jar to /home/kso/work/projects/oasp/devel/java/oasp4j-sample/oasp4j-example-application/target/dependency/cxf-rt-databinding-jaxb-3.0.2.jar
[INFO] Copying jaxb-impl-2.2.10-b140310.1920.jar to /home/kso/work/projects/oasp/devel/java/oasp4j-sample/oasp4j-example-application/target/dependency/jaxb-impl-2.2.10-b140310.1920.jar

@sobkowiak
Copy link
Member

Another interesting finding. When I build in oasp4j-sample directory, the war file includes the version 2.1.14. When building in oasp4j-sample/oasp4j-example-application the version 2.2.10-b140310.1920

@sobkowiak
Copy link
Member

After downgrading to CXF 3.0.0 the I got the same effect -- it means the problem was not caused by any CXF upgrade

@sobkowiak
Copy link
Member

@mmatczak when do you have this problem? I'm starting it from InteliJ and have no problem

@sobkowiak
Copy link
Member

The problem is caused by flatten-maven-plugin

with plugin enabled:

kso@Inspiron-7720:~/work/projects/oasp/devel/java/oasp4j-sample$ mvn clean install -Dmaven.test.skip.exec=true -X | grep jaxb
[DEBUG]          org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.0.2:compile
[DEBUG]             com.sun.xml.bind:jaxb-impl:jar:2.1.14:compile
[DEBUG]             com.sun.xml.bind:jaxb-core:jar:2.1.14:compile
[DEBUG]                javax.xml.bind:jaxb-api:jar:2.1:compile
[DEBUG]       com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.4.2:compile
...

and

kso@Inspiron-7720:~/work/projects/oasp/devel/java/oasp4j-sample/oasp4j-example-application$ mvn clean install -Dmaven.test.skip.exec=true -X | grep jaxb
[DEBUG]          org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.0.2:compile
[DEBUG]             com.sun.xml.bind:jaxb-impl:jar:2.2.10-b140310.1920:compile
[DEBUG]             com.sun.xml.bind:jaxb-core:jar:2.2.10-b140310.1920:compile
[DEBUG]       com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.4.2:compile
...

with plugin disabled:

kso@Inspiron-7720:~/work/projects/oasp/devel/java/oasp4j-sample$ mvn clean install -Dmaven.test.skip.exec=true -X | grep jaxb
[DEBUG]          org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.0.2:compile
[DEBUG]             com.sun.xml.bind:jaxb-impl:jar:2.2.10-b140310.1920:compile
[DEBUG]             com.sun.xml.bind:jaxb-core:jar:2.2.10-b140310.1920:compile
[DEBUG]       com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.4.2:compile
...

and

kso@Inspiron-7720:~/work/projects/oasp/devel/java/oasp4j-sample/oasp4j-example-application$ mvn clean install -Dmaven.test.skip.exec=true -X | grep jaxb
[DEBUG]          org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.0.2:compile
[DEBUG]             com.sun.xml.bind:jaxb-impl:jar:2.2.10-b140310.1920:compile
[DEBUG]             com.sun.xml.bind:jaxb-core:jar:2.2.10-b140310.1920:compile
[DEBUG]       com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.4.2:compile
...

@sobkowiak
Copy link
Member

I have attached build outputs with and without flatten plugin and diff of the both builds

Probably analysis of these files helps

@sobkowiak
Copy link
Member

I should also mention similar problem was reported in CXF community (https://issues.apache.org/jira/browse/CXF-5894) but was rejected.

@sobkowiak
Copy link
Member

To clarify the problem: when using JDK 7, the sample war should contain JAXB in version 2.2.10-* (required by CXF). 2.1.14 should be used when using JDK 6 not having JAXB 2.2. APIs.

@sobkowiak
Copy link
Member

@hohwille as I know you should known very good internals of the flatten plugin. Could you check why it makes problems with building the war file?

hohwille added a commit that referenced this issue Dec 15, 2014
@hohwille
Copy link
Member

@sobkowiak thanks for investigation and figuring this out. To fix this issue I disabled flatten here.
However, I still have to find the actual root of the problem. Therefore I will file an issue for flatten-maven-plugin.

@hohwille hohwille added this to the oasp:1.0.0 milestone Dec 15, 2014
@hohwille hohwille self-assigned this Dec 15, 2014
@sobkowiak
Copy link
Member

Removing the plugin from oasp4j-sample-server haven't solved this problem because it is still enabled in the root pom (https://github.com/oasp/oasp4j/blob/develop/pom.xml#L38-L62). The plugin should be romoved from the root pom.

@hohwille
Copy link
Member

There are two issues here:

  1. http://jira.codehaus.org/browse/MOJO-2041 - this is an easy one for me and I can fix that soon. Until that we decoupled our BOM from the parent.
  2. Some interference of the maven reactor is causing a wrong dependency version resolution for jaxb-*. If flatten is active and I install the modules and then the samples separately in two builds everything works fine so it is not a general bug in flatten plugin.

So far we have some workarounds to build the WAR correctly and still being able to create proper releases.

hohwille added a commit that referenced this issue Dec 15, 2014
@sobkowiak
Copy link
Member

I could reproduce this problem. It appears when from any reason the war file contains both versions of JAXB. So it's not CXF problem but problem with building war file and flatten plugin.

@hohwille hohwille modified the milestones: backlog, oasp:1.0.0 Jan 9, 2015
@hohwille
Copy link
Member

As we now have new versions of flatten available, we shall give it another try.
Current state is in-acceptable if you both develop OASP and an OASP-based app on the same machine with a shared local maven repo as parent POMs with dev versions cause chaos.

@hohwille
Copy link
Member

I have fixed the bug tonight. We can update flatten-maven-plugin to 1.0.0 as soon as it is released. Then we can close this issue.

hohwille added a commit that referenced this issue Dec 7, 2015
@hohwille
Copy link
Member

hohwille commented Dec 7, 2015

Done.

@hohwille hohwille closed this as completed Dec 7, 2015
hohwille added a commit to oasp-forge/oasp4j-spring-boot that referenced this issue Dec 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants