JAXB mixed versions? undefined 'required' attribute

12,221

Solution 1

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.

Solution 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.

Solution 3

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>

Solution 4

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  
Share:
12,221
Borja Coalla
Author by

Borja Coalla

Updated on August 01, 2022

Comments

  • Borja Coalla
    Borja Coalla almost 2 years

    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>
    
  • ulab
    ulab almost 7 years
    looking for this!