开发者

Set Java Compliance Level in CXF wsdl2java

开发者 https://www.devze.com 2023-02-24 20:19 出处:网络
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 se

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?


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


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

精彩评论

暂无评论...
验证码 换一张
取 消