【问题标题】:JAXB mixed versions? undefined 'required' attributeJAXB 混合版本?未定义的“必需”属性
【发布时间】:2014-08-03 19:21:55
【问题描述】:

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

我正在使用 jaxb 2.2.7 并从 mule 库中删除版本 2.1.9 并替换为 2.2.7。

当我编译时,sometines 工作正常,但其他人我多次出现此错误:

The attribute required is undefined for the annotation type XmlElementRef   

我尝试在 JDK 中创建一个背书文件夹并包含所需的 .jar,

您知道有什么方法可以避免此错误或正确替换此库吗?

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

【问题讨论】:

  • 背书的 jar 的路径是什么?
  • 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\认可
  • 如果你知道一种彻底重建的方法

标签: java jaxb jax-ws mule java-7


【解决方案1】:

我们可以通过替换 Mule CE 运行时文件夹 (C:\AnypointStudio\plugins\org.mule.tooling.server.3.5.0_3.5.0.201405141856\骡\lib\opt):

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

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

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

如果 Mule 开发人员将这些软件包更新到最新的发行版,那将会很有用。

【讨论】:

    【解决方案2】:

    您认可的罐子的位置不正确。应该是:

    %JAVA_HOME%\jre\lib\endorsed

    在你的情况下是:

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

    将 jaxb jar 放在此处,删除所有其他 jar 并重试。

    【讨论】:

      【解决方案3】:

      这适用于从搜索引擎中找到此旧帖子的人。

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

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

        • 正在寻找这个!
        猜你喜欢
        • 2014-07-03
        • 1970-01-01
        • 2014-04-22
        • 2019-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-25
        • 1970-01-01
        相关资源
        最近更新 更多