有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JAXB混合版本?未定义的“必需”属性

我使用wsimport maven plugin@Mule Anypoint Studio 3.5和JDK 1.755从WSDL文件生成一些类

我使用的是JAXB2.2.7,从mule libs中删除了2.1.9版,取而代之的是2.2.7版

当我编译时,有些代码可以正常工作,但有些代码会多次出现此错误:

The attribute required is undefined for the annotation type XmlElementRef   

我试着在JDK中创建一个被认可的文件夹并包含它。需要罐子

您知道如何避免此错误或正确替换此LIB吗

我在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是2.2.7到

wsimport设置:

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

共 (4) 个答案

  1. # 1 楼答案

    这是为那些从搜索引擎中找到这篇旧帖子的人准备的

    我在Eclipse中创建的一个新项目中收到了相同的错误消息。解决办法是:

    1.) create a new JAXB project instead of some other project type,  
    2.) specify JDK7,  
    3.) Specify version 2.2 of JAXB  
    
  2. # 2 楼答案

    我们可以通过替换Mule CE运行时文件夹中的以下JAR来修复上述行为(C:\AnypointStudio\plugins\org.Mule.tooling.server.3.5.0_3.5.0.201405141856\Mule\lib\opt):

    jaxb-api-2.1jaxb-api-2.2。jar

    jaxb-impl-2.1.9withjaxb-impl-2.2.7。jar

    jaxb-xjc-2.1.9jaxb-xjc-2.2.7。jar

    如果Mule开发人员将这些包更新到最新的发行版,这将非常有用

  3. # 3 楼答案

    在Mule特定的情况下,如果您仍然使用JAXB2。1,您可以强制Apache CXF WSDL2Java生成JAXB2。1兼容的客户端代码

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

    关键部分是

    <defaultOptions>
      <frontEnd>jaxws21</frontEnd>
    </defaultOptions>
    
  4. # 4 楼答案

    您背书的罐子的位置不正确。应该是:

    %JAVA_HOME%\jre\lib\endorsed

    在你的情况下,这是:

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

    将jaxb JAR放在这里,移除所有其他jaxb JAR,然后重试