在 CXF wsdl2java 中设置 Java 合规性级别

发布于 2024-11-01 03:07:24 字数 2325 浏览 0 评论 0原文

我是 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()

似乎

[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”元素,服务的新构造函数),但 CXF Maven 依赖项适用于 Java 5。

有没有办法指定生成的代码应符合 Java 5?

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

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

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞清仓 2024-11-08 03:07:24

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

有几个选项:

1) 最简单的方法是在 wsdl2java 命令中添加“-fe jaxws21”,使其生成符合 jaxws 2.1 标准的代码而不是 2.2

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

3) 配置maven 中的编译器插件“认可”2.2 jar

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.

There are a few options:

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) Add the 2.2 api jars to the endorsed directory of your JDK

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

护你周全 2024-11-08 03:07:24

wsdl2java 文档 没有提到任何用于指定 Java 版本的选项。

您可以尝试使用 Maven cxf-codegen-plugin 生成客户端存根,它应该尊重 Maven 编译器的源版本和目标版本。

如果这不起作用,您可以通过更改 pom 中的源行和目标行来将 Maven 配置为使用 Java 6,如下所示:

               <source>1.6</source>
               <target>1.6</target>

The wsdl2java documentation doesn't mention any options for specifying the Java version.

You could try using the Maven cxf-codegen-plugin to generate the client stubs, which should respect the Maven compiler's source and target versions.

If that doesn't work, you could configure Maven to use Java 6 by changing the source and target lines in the pom, like so:

               <source>1.6</source>
               <target>1.6</target>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文