在CXF wsdl2java中设置Java合规性级别 [英] Set Java Compliance Level in CXF wsdl2java

查看:73
本文介绍了在CXF wsdl2java中设置Java合规性级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CXF的新手,正在尝试通过WSDL创建一个客户端。我过去曾使用Metro和Axis。我下载了apache-cxf-2.3.3,并使用wsdl2java生成了客户端存根。我使用Maven并将其设置为pom:

I’m brand new to CXF and am trying to create a client from WSDL. I have used Metro and Axis in the past. I downloaded apache-cxf-2.3.3 and used wsdl2java to generate the client stubs. I use Maven and set it up my pom with this:

<properties>
    <cxf.version>2.3.3</cxf.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-ws-security</artifactId>
        <version>${cxf.version}</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <inherited>true</inherited>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
                <optimize>true</optimize>
                <debug>true</debug>
            </configuration>
        </plugin>
    </plugins>
</build>

在构建项目时,出现以下错误:

When I build the project, I get these errors:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project client-cxf: Compilation failure: Compilation failure:
[ERROR] \Devel\Projects\Client-CXF\src\main\java\my\webservice\ServiceRuntimeException.java:[38,149] cannot find symbol
[ERROR] symbol  : method required()

[ERROR] \Devel\Projects\Client-CXF\src\main\java\my\snmpv2\MyService.java:[76,8] cannot find symbol
[ERROR] symbol  : constructor Service(java.net.URL,javax.xml.namespace.QName,javax.xml.ws.WebServiceFeature[])
[ERROR] location: class javax.xml.ws.Service

看来问题出在与以下事实有关:生成的代码使用Java 6功能(XmlElementRef为 require元素,Service为新构造函数) CXF Maven依赖项是针对Java 5的。

It appears that the problems are related to the fact that the generated code uses Java 6 features ("require" element for XmlElementRef, new constructors for Service) yet the CXF Maven dependencies are for Java 5.

是否可以指定生成的代码是否符合Java 5?

Is there a way to specify that the generated code should be Java 5 compliant?

推荐答案

实际上,CXF的wsdl2java命令行工具与Java 5兼容的代码,它很可能与Java 6不兼容。原因是它生成的代码是JAX -符合WS 2.2和JAXB 2.2。但是,Java 6中包含的那些API的版本仅为2.1。

Actually, the code that CXF's wsdl2java command line tool is compatible with Java 5, it's just likely not compatible for Java 6. The reason is that it generates code that is JAX-WS 2.2 and JAXB 2.2 compliant. However, the versions of those API's included in Java 6 are only 2.1.

有一些选择:

1)最简单的方法是在wsdl2java命令中添加 -fe jaxws21,以使其生成与jaxws 2.1兼容的代码,而不是2.2

1) Easiest is to add "-fe jaxws21" to the wsdl2java command to have it generate jaxws 2.1 compliant code instead of 2.2

2)将2.2 api罐添加到JDK的认可目录

2) Add the 2.2 api jars to the endorsed directory of your JDK

3)在maven中配置编译器插件以认可 2.2个jars

3) Configure the compiler plugin in maven to "endorse" the 2.2 jars

这篇关于在CXF wsdl2java中设置Java合规性级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆