5
votes

Is there a comprehendable tutorial out there that shows how to generate a WSDL from java code using maven and the cxf goal java2ws?

I want to execute mvn install on a project containing a @WebService annotated class and have the WSDL generated somewhere inside the target folder so the other developer can use it to generate the subscriber classes.

Also I want the Webservice to get included into a jar that I can deploy inside a WebService container so the service will be available for the subscriber.

So far my pom looks like this:

<properties>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <cxf.version>2.2.3</cxf.version>
</properties>


<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-frontend-jaxws</artifactId>
                        <version>2.0.9</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>generate-wsdl</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>java2ws</goal>
                        </goals>
                        <configuration>
                            <outputFile>${project.build.outputDirectory}/testService.wsdl</outputFile> 
                            <className>complete.path.to.ClassName</className>
                            <verbose>true</verbose>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>


<pluginRepositories>
    <pluginRepository>
        <id>apache-snapshots</id>
        <name>Apache SNAPSHOT Repository</name>
        <url>http://repository.apache.org/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>


<repositories>
    <repository>
        <id>apache-snapshots</id>
        <name>Apache SNAPSHOT Repository</name>
        <url>http://repository.apache.org/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>maven2-repository.dev.java.net</id>
        <name>Java.net Repository for Maven</name>
        <url>http://download.java.net/maven/2/</url>
        <layout>default</layout>
    </repository>
</repositories>


<dependencies>
    <!-- CXF WebService -->
    <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-transports-http-jetty</artifactId>
        <version>${cxf.version}</version>
    </dependency>
</dependencies>

But when I run maven install.. no wsdl..

Oh right, additional information: We're developing in a modular fashion. The module that provides the WebService will contain other classes that handle internal method calls from the frontend module and will be built as a jar and not a war.

Hope someone finds what I'm missing or can point me to a good tutorial.

EDIT: Invoked the goal directly with mvn org.apache.cxf:cxf-java2ws-plugin:java2ws but I get a LifecycleExecutionException:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.cxf:cxf-java2ws-plugin:2.2.3:java2ws (default-cli) on project dw-person: The parameters 'className' for goal o
rg.apache.cxf:cxf-java2ws-plugin:2.2.3:java2ws are missing or invalid
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:221)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginParameterException: The parameters 'className' for goal org.apache.cxf:cxf-java2ws-plugin:2.2.3:java2ws are missing or invalid
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:576)
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:529)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:92)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        ... 19 more

The className parameter exists however as seen above and the path is correct as well... Any ideas?

3

3 Answers

2
votes

Just for those who have troubles not connected with pluginManagement. In my case, for cxf.version 3.1.10 the matter was in placing of <configuration> section. After moving it up to the same level as <executions> is, the problem has gone. I've found it here: http://cxf.547215.n5.nabble.com/Strange-behavior-of-Maven-cxf-java2ws-plugin-td553742.html

Here is example from apache.org (https://cxf.apache.org/docs/maven-java2ws-plugin.html):

<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>${cxf.version}</version>
<dependencies>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
</dependencies>

<executions>
    <execution>
        <id>process-classes</id>
        <phase>process-classes</phase>
        <configuration>
            <className>full.class.name</className>
            <genWsdl>true</genWsdl>
            <verbose>true</verbose>
        </configuration>
        <goals>
            <goal>java2ws</goal>
        </goals>
    </execution>
</executions>
</plugin>

And here is fixed one:

<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-java2ws-plugin</artifactId>
<version>${cxf.version}</version>
<dependencies>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>      
</dependencies>

<configuration>
    <className>full.class.name</className>
    <genWsdl>true</genWsdl>
    <verbose>true</verbose>
</configuration> 

<executions>
    <execution>
        <id>process-classes</id>
        <phase>process-classes</phase>
        <goals>
            <goal>java2ws</goal>
        </goals>
    </execution>
</executions>
</plugin>
1
votes

Looks like the tag <pluginManagement> is unknown. If I remove it (and update to cxf version 2.5), everything works nicely even for just .jar packaging.

No idea why it can be found everywhere on the web with the tag. Also wondering why these kinds of errors are not detected or logged by maven. sigh...

0
votes
Good Read - http://united-coders.com/phillip-steffensen/developing-a-simple-soap-webservice-using-spring-301-and-apache-cxf-226


<project xmlns="...">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.unitedcoders.demo</groupId>

    <artifactId>CXFExampleService</artifactId>

    <packaging>war</packaging>

    <version>0.0.1-SNAPSHOT</version>

    <name>Example Apache CXF Webservice</name>

    <url>http://united-coders.com</url>



    <!-- Dependency properties -->

    <properties>

        <junit-version>4.5</junit-version>

        <cxf.version>2.2.6</cxf.version>

        <spring-version>3.0.1.RELEASE</spring-version>

        <commons-logging-version>1.1.1</commons-logging-version>

    </properties>



    <!-- Plugin configuration -->

    <build>

        <finalName>CXFExampleService</finalName>

        <plugins>

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-compiler-plugin</artifactId>

                <configuration>

                    <source>1.6</source>

                    <target>1.6</target>

                </configuration>

            </plugin>

            <plugin>

                <groupId>org.apache.cxf</groupId>

                <artifactId>cxf-java2ws-plugin</artifactId>

                <version>${cxf.version}</version>

                <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-frontend-simple</artifactId>

                        <version>${cxf.version}</version>

                    </dependency>

                </dependencies>

                <executions>

                    <execution>

                        <id>process-classes</id>

                        <phase>process-classes</phase>

                        <configuration>

                            <className>com.unitedcoders.demo.PersonService</className>

                            <genWsdl>true</genWsdl>

                            <verbose>true</verbose>

                        </configuration>

                        <goals>

                            <goal>java2ws</goal>

                        </goals>

                    </execution>

                </executions>

            </plugin>

        </plugins>

    </build>



    <!-- Dependency definitions -->

    <dependencies>



        <!-- Apache CXF 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>



        <!-- Spring Dependencies -->

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-core</artifactId>

            <version>${spring-version}</version>

        </dependency>

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-web</artifactId>

            <version>${spring-version}</version>

        </dependency>



        <!-- Logging -->

        <dependency>

            <groupId>commons-logging</groupId>

            <artifactId>commons-logging</artifactId>

            <version>${commons-logging-version}</version>

        </dependency>



        <!-- Testing -->

        <dependency>

            <groupId>junit</groupId>

            <artifactId>junit</artifactId>

            <version>${junit-version}</version>

            <scope>test</scope>

        </dependency>

    </dependencies>

</project>