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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24201825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 10:46:25  来源:igfitidea点击:

JAXB mixed versions? undefined 'required' attribute

javajaxbjax-wsmulejava-7

提问by Borja Coalla

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

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

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

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

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

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

The attribute required is undefined for the annotation type XmlElementRef   

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

我试图在 JDK 中创建一个认可的文件夹并包含需要的 .jars,

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

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

I include this dependencies in pom.xml

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

wsimport settings:

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>

采纳答案by Borja Coalla

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

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

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

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

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

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

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

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

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

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

回答by JamesB

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

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

%JAVA_HOME%\jre\lib\endorsed

%JAVA_HOME%\jre\lib\endorsed

which in your case is:

在你的情况下是:

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

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

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

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

回答by CodeMed

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:

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

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

回答by Boris Treukhov

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

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

the key part is

关键部分是

<defaultOptions>
  <frontEnd>jaxws21</frontEnd>
</defaultOptions>