Deploying the JAX-WS application with Maven

In this section, we will compile, package, and deploy the jboss-jaxws application to WildFly 8.1. Specify the JAX-WS-related dependencies discussed in the following table in the pom.xml file:

Dependency

Description

Group Id: com.sun.xml.ws

Artifact Id: jaxws-rt

Open source reference implementation of the JSR 224: Java API for XML Web Services

Group Id: javax.xml.ws

Artifact Id: jaxws-api

JAX-WS (JSR 224) API

Group Id: com.sun.xml.bind

Artifact Id: jaxb-impl

JAXB (JSR 222) Reference implementation

Group Id: com.sun.xml.bind

Artifact Id: jaxb-xjc

JAXB (JSR 222) Reference implementation-schema compiler

We will use the JAX-WS Maven Plugin (http://jax-ws-commons.java.net/jaxws-maven-plugin/), which is the Maven adapter for the JAX-WS's toolset. The plugin provides wsgen and wsimport goals to generate the required portable artifacts for a web service. First, run the wsgen goal to generate the JAX-WS web service portable artifacts, including the WSDL, from an endpoint implementation class. Subsequently, run the wsimport goal to generate the web service portable artifacts, used by web service clients, from a WSDL. For the wsgen goal, specify the service endpoint interface in the <sei/> element as org.jboss.jaxws.service.HelloWorld, and specify the service name in the <serviceName/> element as HelloWorldService. Set <genwsdl/> for the wsgen goal to true. Specify the Maven Compiler Plugin and the Maven WAR Plugin, with the output directory set to the deployments directory. The pom.xml code is listed here:

<?xml version="1.0" encoding="UTF-8"?>
<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.jaxws</groupId>
  <artifactId>jboss-jaxws</artifactId>
  <version>1.0.0</version>
  <packaging>war</packaging>
  <name>Java EE 7 webapp project</name>
  <description>A starter Java EE 7 webapp project for use on JBoss 
  WildFly / WildFly, generated from the jboss-javaee6-webapp 
  archetype</description>
  <url>http://wildfly.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-
    8</project.build.sourceEncoding>
    <!-- JBoss dependency versions -->
    <version.wildfly.maven.plugin>1.0.2.Final </version.wildfly.maven.plugin>
    <!-- Define the version of the JBoss BOMs we want to import to specify 
      tested stacks. -->
    <version.jboss.bom>8.1.0.Final</version.jboss.bom>
    <!-- other plugin versions -->
    <version.compiler.plugin>3.1</version.compiler.plugin>
    <version.war.plugin>2.1.1</version.war.plugin>
    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>
  </properties>
  <repositories>
    <repository>
      <id>JBoss Repository</id>
      <url>https://repository.jboss.org/nexus/content /groups/public/</url>
    </repository>
  </repositories>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.wildfly.bom</groupId>
        <artifactId>jboss-javaee-7.0-with-tools</artifactId>
        <version>${version.jboss.bom}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.wildfly.bom</groupId>
        <artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
        <version>${version.jboss.bom}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <!-- First declare the APIs we depend on and need for compilation. All of them are provided by JBoss WildFly -->
    <!-- Import the CDI API, we use provided scope as the API is included in 
      JBoss WildFly -->
    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>jaxws-rt</artifactId>
      <version>2.2.8</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.xml.ws</groupId>
      <artifactId>jaxws-api</artifactId>
      <version>2.2.8</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-impl</artifactId>
      <version>2.2.7</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>
    <!-- Import the Common Annotations API (JSR-250), we use provided scope 
      as the API is included in JBoss WildFly -->
    <dependency>
      <groupId>org.jboss.spec.javax.annotation</groupId>
      <artifactId>jboss-annotations-api_1.2_spec</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
      <version>2.2.7</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <!-- Maven will append the version to the finalName (which is the name 
      given to the generated war, and hence the context root) -->
    <finalName>${project.artifactId}</finalName>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.jvnet.jax-ws-commons</groupId>
                    <artifactId>jaxws-maven-plugin</artifactId>
                    <versionRange>[2.2,)</versionRange>
                    <goals>
                      <goal>wsimport</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <ignore />
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </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>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>${version.war.plugin}</version>
          <configuration>
            <outputDirectory>C:wildfly-8.1.0.Finalstandalonedeployments</outputDirectory>
            <!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
            <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
        </plugin>
        <!-- The WildFly plugin deploys your war to a local WildFly container -->
        <!-- To use, run: mvn package wildfly:deploy -->
        <plugin>
          <groupId>org.wildfly.plugins</groupId>
          <artifactId>wildfly-maven-plugin</artifactId>
          <version>${version.wildfly.maven.plugin}</version>
        </plugin>
        <plugin>
          <groupId>org.jvnet.jax-ws-commons</groupId>
          <artifactId>jaxws-maven-plugin</artifactId>
          <version>2.2</version>
          <executions>
            <execution>
              <id>HelloWorldService</id>
              <phase>compile</phase>
              <goals>
                <goal>wsgen</goal>
              </goals>
              <configuration>
                <sei>org.jboss.jaxws.service.HelloWorld</sei>
                <genwsdl>true</genwsdl>
                <servicename>HelloWorldService</servicename>
                <keep>true</keep>
              </configuration>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.jvnet.jax-ws-commons</groupId>
          <artifactId>jaxws-maven-plugin</artifactId>
          <version>2.3</version>
          <executions>
            <execution>
              <id>HelloWorldService</id>
              <goals>
                <goal>wsimport</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <packagename>org.jboss.jaxws.service</packagename>
            <target>2.0</target>
            <keep>true</keep>
          </configuration>
          <dependencies>
            <dependency>
              <groupId>com.sun.xml.ws</groupId>
              <artifactId>jaxws-tools</artifactId>
              <version>2.2.8</version>
              <exclusions>
                <exclusion>
                  <groupId>org.jvnet.staxex</groupId>
                  <artifactId>stax-ex</artifactId>
                </exclusion>
              </exclusions>
            </dependency>
            <dependency>
              <groupId>org.jvnet.staxex</groupId>
              <artifactId>stax-ex</artifactId>
              <version>1.7.6</version>
              <exclusions>
                <exclusion>
                  <groupId>javax.xml.stream</groupId>
                  <artifactId>stax-api</artifactId>
                </exclusion>
              </exclusions>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

Right-click on pom.xml in the Project Explorer and select Run As | Maven install, as shown in the following screenshot:

Deploying the JAX-WS application with Maven

The jboss-jaxws project gets compiled and packaged into a jboss-jaxws.war archive. A BUILD SUCCESS message indicates that the Maven build completed without any error, as shown here:

Deploying the JAX-WS application with Maven

Start WildFly 8.1 if it is not already started. The jboss-jaxws.war archive gets deployed to WildFly 8.1, as shown in the Administration console:

Deploying the JAX-WS application with Maven

The WSDL for the web service can be invoked in a browser with the URL http://localhost:8080/jboss-jaxws/HelloWorld?WSDL, as shown in the following screenshot:

Deploying the JAX-WS application with Maven

The WSDL file's content is shown as follows:

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"xmlns:tns="http://org.jboss.jaxws.service/"xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:ns1="http://schemas.xmlsoap.org/soap/http"name="HelloWorl dService"targetNamespace="http://org.jboss.jaxws.service/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns:tns="http://org.jboss.jaxws.service/"elementFormDefault="unqualified"tar getNamespace="http://org.jboss.jaxws.service/" version="1.0">
<xs:element name="hello" type="tns:hello"/>
<xs:element name="helloResponse" type="tns:helloResponse"/>
<xs:complexType name="hello">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="helloResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="hello">
<wsdl:part element="tns:hello" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="helloResponse">
<wsdl:part element="tns:helloResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:portType name="HelloWS">
<wsdl:operation name="hello">
<wsdl:input message="tns:hello" name="hello"></wsdl:input>
<wsdl:output message="tns:helloResponse"name="helloResponse"> </wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldServiceSoapBinding" type="tns:HelloWS">
<soap:binding style="document"transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="hello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="hello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="helloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldService">
<wsdl:port binding="tns:HelloWorldServiceSoapBinding" name="HelloWorldPort">
<soap:address location="http://localhost:8080/jboss-jaxws/HelloWorld"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset