10

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?

Machavity
  • 30,841
  • 27
  • 92
  • 100
sdoca
  • 7,832
  • 23
  • 70
  • 127

2 Answers2

25

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

Daniel Kulp
  • 14,447
  • 4
  • 45
  • 37
  • Thanks for the clarification about the compatibilities and using the -fe option. The description on http://cxf.apache.org/docs/wsdl-to-java.html doesn't explain it well and that one can designate which jax-ws version to use. – sdoca Apr 14 '11 at 17:05
  • which version of frontend to set for JDK8? Currently in my lagacy project there set jaxws21 but it looks outdated – Sergey Ponomarev Aug 07 '18 at 18:36
0

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>
Powerlord
  • 87,612
  • 17
  • 125
  • 175
  • I didn't think Glassfish has a version of wsdl2java. I've used wsimport when generating Metro clients. Axis has a wsdl2java, but I don't have it currently installed. Using the cxf-codegen-plugin creates the same Java 6 code. – sdoca Apr 13 '11 at 21:46
  • I'm sorry, you're right. It's `wsimport` for the Metro version. – Powerlord Apr 13 '11 at 22:01