我是 CXF 的新手,正在尝试从 WSDL 创建客户端。我过去使用过 Metro 和 Axis。我下载了 apache-cxf-2.3.3 并使用 wsdl2java 生成客户端存根。我使用 Maven 并使用以下命令设置我的 pom:
<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>
当我构建项目时,我收到以下错误:
[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()
and
[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。
有没有办法指定生成的代码应该符合 Java 5?
实际上,CXF 的 wsdl2java 命令行工具的代码与 Java 5 兼容,只是可能与 Java 6 不兼容。原因是它生成的代码兼容 JAX-WS 2.2 和 JAXB 2.2。然而,Java 6 中包含的这些 API 的版本仅为 2.1。
有以下几种选择:
1) 最简单的方法是将“-fe jaxws21”添加到 wsdl2java 命令中,使其生成 jaxws 2.1 兼容代码而不是 2.2
2) 将 2.2 api jar 添加到 JDK 的认可目录中
3)在maven中配置编译器插件以“认可”2.2 jar
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)