JAXB mixed versions? undefined 'required' attribute
Asked Answered
K

4

8

Im generating some classes from WSDL files with wsimport maven plugin @ Mule Anypoint Studio 3.5 with JDK 1.7_55

I'm using jaxb 2.2.7 and remove version 2.1.9 from mule libs and replaced by 2.2.7.

When i compile, sometines works fine but others i take this error multiple times:

The attribute required is undefined for the annotation type XmlElementRef   

I tried to create an endorsed folder in JDK and include .jars needed,

Do you know any way to avoid this error or replace this libs correctly?

I include this dependencies in pom.xml

<dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-tools</artifactId>
        <version>2.2.7</version>
    </dependency>

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.7</version>
    </dependency>
    <!-- xjc -->
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-xjc</artifactId>
        <version>2.2.7</version>
    </dependency>
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.7</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>idlj-maven-plugin</artifactId>
        <version>1.2.1</version>
    </dependency>       

wsimport is 2.2.7 to

wsimport settings:

<plugin>
            <groupId>org.jvnet.jax-ws-commons</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
                <execution>
                    <id>wsdl-AMANSequenceService-exec</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <args>
                            <arg>-version</arg>
                            <arg>-B-nv</arg>
                            <arg>-Xdebug</arg>
                            <arg>-B-XautoNameResolution</arg>
                            <arg>-Xendorsed</arg>
                        </args>
                        <extension>true</extension>
                        <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                        <destDir>${basedir}/src/main/java</destDir>
                        <extension>true</extension>
                        <wsdlDirectory>${basedir}/src/main/resources/SICG/AMANSequenceService</wsdlDirectory>
                        <wsdlFiles>
                            <wsdlFile>AMANSequenceService.wsdl</wsdlFile>
                        </wsdlFiles>
                        <bindingFiles>
                            <bindingFile>${basedir}/src/main/resources/SICG/external/binding.xjb</bindingFile>
                        </bindingFiles>
                    </configuration>
                </execution>
Keslie answered 13/6, 2014 at 9:18 Comment(3)
What is the path for the endorsed jars?Ropable
C:\Java\jdk1.7.0_55\lib\endorsed\jaxb-api-2.2.jar C:\Java\jdk1.7.0_55\lib\endorsed\jaxb-impl-2.2.7.jar C:\Java\jdk1.7.0_55\lib\endorsed\jaxb-xjc-2.2.7.jar C:\AnypointStudio\plugins\org.mule.tooling.server.3.5.0_3.5.0.201405141856\mule\lib\endorsedKeslie
if u know a way to do a clean rebuildKeslie
K
4

We can fix the above behavior by replacing the following jars in Mule CE Runtime Folder (C:\AnypointStudio\plugins\org.mule.tooling.server.3.5.0_3.5.0.201405141856\mule\lib\opt):

jaxb-api-2.1 with jaxb-api-2.2.jar

jaxb-impl-2.1.9 with jaxb-impl-2.2.7.jar

jaxb-xjc-2.1.9 with jaxb-xjc-2.2.7.jar

It would be useful if Mule developers updated these packages to the newest distributions.

Keslie answered 16/6, 2014 at 11:22 Comment(0)
R
2

The location of your endorsed jars is incorrect. It should be:

%JAVA_HOME%\jre\lib\endorsed

which in your case is:

C:\Java\jdk1.7.0_55\jre\lib\endorsed

Put the jaxb jars here, remove all others and re-try.

Ropable answered 13/6, 2014 at 9:50 Comment(0)
I
1

This is for people who find this old posting from the search engines.

I was getting the same error message in a new project that I created in Eclipse. The solution was to:

1.) create a new JAXB project instead of some other project type,  
2.) specify JDK7,  
3.) Specify version 2.2 of JAXB  
Inattention answered 23/9, 2014 at 21:34 Comment(0)
O
1

In Mule specific case, if you are stuck with JAXB2.1, you can force Apache CXF WSDL2Java to generate JAXB2.1 compliant client code

<plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.1.6</version>
                <executions>
                    <execution>
                        <id>generate-sources-file1</id>
                        <phase>generate-sources</phase>
                        <configuration>
                        <defaultOptions>
                            <frontEnd>jaxws21</frontEnd>
                        </defaultOptions>
                            <sourceRoot>${project.build.directory}/generated/service-file1</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/some.wsdl</wsdl>
                                    <wsdlLocation>classpath:some.wsdl</wsdlLocation>
                                    <extraargs>
                                        <extraarg>-client</extraarg>
                                        <extraarg>-verbose</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>

                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
                </plugin>

the key part is

<defaultOptions>
  <frontEnd>jaxws21</frontEnd>
</defaultOptions>
Oxygen answered 22/7, 2016 at 15:26 Comment(1)
looking for this!Greenroom

© 2022 - 2024 — McMap. All rights reserved.