Version 4

    Here is an example of usage of the JBossWS JAXWS Tools Maven plugin; in particular we'll be using the wsconsume tool, which generates sources for a given wsdl endpoint.

     

    You start by building a basic maven based app, using a pom.xml file as below:

     

    <?xml version="1.0"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>org.jboss.ws.samples</groupId>
       <artifactId>wsconsume-plugin-sample</artifactId>
       <version>1.0.0-SNAPSHOT</version>
       <packaging>war</packaging>
       <name>JBossWS wsconsume maven plugin sample</name>
       <description>JBossWS wsconsume maven plugin sample</description>
       <url>http://www.jboss.org</url>
    
       <properties>
          <!-- Explicitly declaring the source encoding eliminates the following message: -->
          <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! -->
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    
          <!-- JBoss dependency versions -->
          <version.org.jboss.as.plugins.maven.plugin>7.3.Final</version.org.jboss.as.plugins.maven.plugin>
          <version.org.jboss.spec.jboss.javaee.6.0>3.0.0.Final</version.org.jboss.spec.jboss.javaee.6.0>
    
          <!-- other plugin versions -->
          <version.compiler.plugin>2.3.1</version.compiler.plugin>
    
          <!-- maven-compiler-plugin -->
          <maven.compiler.target>1.6</maven.compiler.target>
          <maven.compiler.source>1.6</maven.compiler.source>
       </properties>
    
    
       <dependencyManagement>
          <dependencies>
             <!-- Define the version of JBoss' Java EE 6 APIs we want to import. 
                Any dependencies from org.jboss.spec will have their version defined by this 
                BOM -->
             <!-- JBoss distributes a complete set of Java EE 6 APIs including
                a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or
                a collection) of artifacts. We use this here so that we always get the correct
                versions of artifacts. Here we use the jboss-javaee-6.0 stack (you can
                read this as the JBoss stack of the Java EE 6 APIs). You can actually
                use this stack with any version of JBoss AS that implements Java EE 6, not
                just JBoss AS 7! -->
             <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-6.0</artifactId>
                <version>${version.org.jboss.spec.jboss.javaee.6.0}</version>
                <type>pom</type>
                <scope>import</scope>
             </dependency>
          </dependencies>
       </dependencyManagement>
    
    
       <dependencies>
    
       </dependencies>
    
       <build>
          <!-- Set the name of the war, used as the context root when the app is deployed -->
          <finalName>wsconsume-plugin-sample</finalName>
          <plugins>
             <plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <version>${version.org.jboss.as.plugins.maven.plugin}</version>
             </plugin>
             <!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation processors -->
             <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                 <version>${version.compiler.plugin}</version>
                 <configuration>
                     <source>${maven.compiler.source}</source>
                     <target>${maven.compiler.target}</target>
                </configuration>
             </plugin>
          </plugins>
       </build>
    
    </project>
    

     

    The pom simply uses the maven compiler plugin and the jboss-as-maven-plugin that will later deploy our app to JBoss AS 7. Please note the JBoss JavaEE 6 spec artifacts. The JBoss Maven repository of course needs to be properly setup in your environment.

    Then you simply add the JBossWS dependency needed by the wsconsume tool (provided scope to avoid it being added to the deployable archive) as well as the jaxws-tools plugin for running wsconsume:

     

    <dependencies>
          <dependency>
                        <groupId>org.jboss.ws.cxf</groupId>
                        <artifactId>jbossws-cxf-client</artifactId>
                        <version>4.1.1.Final</version>
                        <scope>provided</scope>
          </dependency>
    </dependencies>
    

     

     

    <build>
       ...
            <plugin>
              <groupId>org.jboss.ws.plugins</groupId>
              <artifactId>maven-jaxws-tools-plugin</artifactId>
              <version>1.1.1.Final</version>
              <configuration>
                <verbose>true</verbose>
              </configuration>
              <executions>
                <execution>
                  <id>My execution</id>
                  <goals>
                    <goal>wsconsume</goal>
                  </goals>
                  <configuration>
                    <wsdls>
                      <wsdl>${basedir}/src/main/resources/test.wsdl</wsdl>
                    </wsdls>
                    <targetPackage>foo.bar</targetPackage>
                  </configuration>
                </execution>
              </executions>
            </plugin>
       ...
    </build>
    
    

     

    The test.wsdl is the WSDL file we're consuming (the contract for the service you want to expose in this case, but it could also be the contract for a service you want to create a client for) and is added to src/main/resources.

    You then add a sample WS endpoint implementation that implements the interface that will be generated by wsconsume at build time:

     

    package org.jboss.ws.samples;
    
    import javax.jws.WebService;
    import foo.bar.Endpoint;
    
    @WebService(endpointInterface = "foo.bar.Endpoint")
    public class EchoEndpointImpl implements Endpoint
    {
       public String echoString(String s)
       {
          return s;
       }
    }
    

     

    and you create a simple web.xml in src/main/webapp/WEB-INF to make your endpoint available in the application:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
       <servlet>
          <servlet-name>echo</servlet-name>
          <servlet-class>org.jboss.ws.samples.EchoEndpointImpl</servlet-class>
       </servlet>
       <servlet-mapping>
          <servlet-name>echo</servlet-name>
          <url-pattern>/echo</url-pattern>
       </servlet-mapping>
    </web-app>
    

     

    That's all! Time to build and deploy the application, it's just a matter of a single mvn command (be sure to have a running AS 7.1 or greater):

     

    alessio@inuyasha /dati/wsconsume-sample $ mvn clean jboss-as:deploy
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building JBossWS wsconsume maven plugin sample 1.0.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ wsconsume-plugin-sample ---
    [INFO] Deleting /dati/wsconsume-sample/target
    [INFO] 
    [INFO] >>> jboss-as-maven-plugin:7.3.Final:deploy (default-cli) @ wsconsume-plugin-sample >>>
    [INFO] 
    [INFO] --- maven-jaxws-tools-plugin:1.1.1.Final:wsconsume (My execution) @ wsconsume-plugin-sample ---
    log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
    log4j:WARN Please initialize the log4j system properly.
    log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
    Loading FrontEnd jaxws ...
    Loading DataBinding jaxb ...
    wsdl2java -exsh false -p foo.bar -d /dati/wsconsume-sample/target/generated-sources/wsconsume -verbose -allowElementReferences file:/dati/wsconsume-sample/src/main/resources/test.wsdl
    wsdl2java - Apache CXF 2.6.4
    
    
    [INFO] 
    [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ wsconsume-plugin-sample ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.3.1:compile (default-compile) @ wsconsume-plugin-sample ---
    [INFO] Compiling 3 source files to /dati/wsconsume-sample/target/classes
    [INFO] 
    [INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ wsconsume-plugin-sample ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 0 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:2.3.1:testCompile (default-testCompile) @ wsconsume-plugin-sample ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.7.2:test (default-test) @ wsconsume-plugin-sample ---
    [INFO] Surefire report directory: /dati/wsconsume-sample/target/surefire-reports
    
    
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    There are no tests to run.
    
    
    Results :
    
    
    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
    
    
    [INFO] 
    [INFO] --- maven-war-plugin:2.1.1:war (default-war) @ wsconsume-plugin-sample ---
    [INFO] Packaging webapp
    [INFO] Assembling webapp [wsconsume-plugin-sample] in [/dati/wsconsume-sample/target/wsconsume-plugin-sample]
    [INFO] Processing war project
    [INFO] Copying webapp resources [/dati/wsconsume-sample/src/main/webapp]
    [INFO] Webapp assembled in [23 msecs]
    [INFO] Building war: /dati/wsconsume-sample/target/wsconsume-plugin-sample.war
    [INFO] WEB-INF/web.xml already added, skipping
    [INFO] 
    [INFO] <<< jboss-as-maven-plugin:7.3.Final:deploy (default-cli) @ wsconsume-plugin-sample <<<
    [INFO] 
    [INFO] --- jboss-as-maven-plugin:7.3.Final:deploy (default-cli) @ wsconsume-plugin-sample ---
    Feb 13, 2013 7:01:42 PM org.xnio.Xnio <clinit>
    INFO: XNIO Version 3.0.7.GA
    Feb 13, 2013 7:01:42 PM org.xnio.nio.NioXnio <clinit>
    INFO: XNIO NIO Implementation Version 3.0.7.GA
    Feb 13, 2013 7:01:42 PM org.jboss.remoting3.EndpointImpl <clinit>
    INFO: JBoss Remoting version 3.2.12.GA
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 7.284s
    [INFO] Finished at: Wed Feb 13 19:01:43 CET 2013
    [INFO] Final Memory: 27M/183M
    [INFO] ------------------------------------------------------------------------
    alessio@inuyasha /dati/wsconsume-sample $
    
    

     

    As you can see the wsconsume plugin is called as part of the build and the generated classes are compile and added into the deployment together with our endpoint implementation. If the wsdl was a more complex one, causing the generation of classes to carry request and response data, those whould have also be included automatically.

     

    You can check the endpoint is available by getting the wsdl at http://localhost:8080/wsconsume-plugin-sample/echo?wsdl

     

    If you want to have a try of the sample here, download the maven project .