Maven POM files

Talend ESB Development Guide

EnrichVersion
6.2
EnrichProdName
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Talend Data Fabric
Talend ESB
Talend MDM Platform
Talend Data Services Platform
task
Design and Development
EnrichPlatform
Talend ESB

This sample consists of four Maven pom.xml files--the top-level pom.xml and one pom.xml file for each of the three submodules. Because they specify the top-level pom as their parent, the latter three all inherit the configuration information in the top-level pom.xml file. Also, because the top-level pom explicitly references each of this submodules, those submodules are processed while running most Maven commands (such as mvn clean install or mvn eclipse:eclipse) from the project base directory. We'll explore this project's pom.xml files in this section.

Top-level pom.xml

This is the parent pom file declaring common dependencies and plugins used by the submodules (service, war, and client).

<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.talend.cxf-examples.dev-guide-wsdl-first</groupId>
    <artifactId>dev-guide-wsdl-first</artifactId>
    <version>6.2.2</version>
    <name>Dev Guide Tutorial: WSDL-First Web Service</name>
    <packaging>pom</packaging>

    <modules>
        <module>service</module>
        <module>war</module>
        <module>client</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cxf.version></cxf.version>
        <spring.version>3.0.7.RELEASE</spring.version>
    </properties>
    <build>
        <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.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                </configuration>
            </plugin>
            <plugin>
               <groupId>org.apache.tomcat.maven</groupId>
               <artifactId>tomcat7-maven-plugin</artifactId>
               <version>2.1</version>
               <configuration>
                  <server>myTomcat</server>
                  <url>http://localhost:8080/manager/text</url>
                  <path>/${project.build.finalName}</path>
               </configuration>
            </plugin>
        </plugins>
    </build>

    <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>
    </dependencies>

</project>

service/pom.xml

This pom file generates the JAX-WS artifacts using CXF's wsdl2java utility that will be used by the web service provider and the SOAP client. The Maven Assembly Plugin is used here to create an additional JAR artifact containing just the JAX-WS objects, which will be later included as a dependency in the client's pom.xml file. JUnit is included for unit testing, which will be shown shortly. The packaging element has a value of "bundle" which will work for both OSGi and servlet deployment, for servlet-only deployment the (very) slightly simpler "jar" value can be used instead.

<project xmlns="http://maven.apache.org/POM/4.0.0" ... 

    <modelVersion>4.0.0</modelVersion>
    <artifactId>dev-guide-wsdl-first-service</artifactId>
    <name>-- Web Service Provider</name>
    <packaging>bundle</packaging>

    <parent>
        <groupId>org.talend.cxf-examples.dev-guide-wsdl-first</groupId>
        <artifactId>dev-guide-wsdl-first</artifactId>
        <version>6.2.2</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Below plugin provides a separate JAR for the JAX-WS artifacts 
                (i.e., the objects created by running wsdl2java or wsimport),  
                as this JAR will also be used by the SOAP client. 
                More info: http://maven.apache.org/plugins/maven-assembly-plugin/ 
            -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/assembly/jaxws-jar.xml</descriptor>
                    </descriptors>
                    <appendAssemblyId>true</appendAssemblyId>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>            
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <configuration>
                            <sourceRoot>
                                ${basedir}/target/generated-sources
                            </sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>
                                        ${basedir}/src/main/resources/DoubleIt.wsdl
                                    </wsdl>
                                    <wsdlLocation>
                                        classpath:DoubleIt.wsdl
                                    </wsdlLocation>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>            
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.5</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>
                            ${project.artifactId}
                        </Bundle-SymbolicName>
                        <Require-Bundle>
                            org.apache.cxf.bundle,org.springframework.beans
                        </Require-Bundle>
                        <Export-Package>service</Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
        <!-- Name of the generated WAR file -->
        <finalName>doubleit</finalName>
    </build>

</project>

war/pom.xml

This pom creates the WAR file that will host the web service if you're using Tomcat. It is not needed for OSGi deployment, but if you omit adding this file be sure to remove this module from the module list in the parent pom.xml.

<project xmlns="http://maven.apache.org/POM/4.0.0" ...

    <modelVersion>4.0.0</modelVersion>
    <artifactId>dev-guide-wsdl-first-war</artifactId>
    <name>-- Service WAR file</name>
    <packaging>war</packaging>
    <url>http://maven.apache.org</url>

    <parent>
        <groupId>org.talend.cxf-examples.dev-guide-wsdl-first</groupId>
        <artifactId>dev-guide-wsdl-first</artifactId>
        <version>6.2.2</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.talend.cxf-examples.dev-guide-wsdl-first</groupId>
            <artifactId>dev-guide-wsdl-first-service</artifactId>
            <version>6.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
               <groupId>org.apache.tomcat.maven</groupId>
               <artifactId>tomcat7-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                    <webResources>
                        <resource>
                            <directory>../service/src/main/resources</directory>
                            <targetPath>WEB-INF/wsdl</targetPath>
                            <includes>
                                <include>*.wsdl</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
        <!-- Name of the generated WAR file -->
        <finalName>doubleit</finalName>
    </build>

</project>

client/pom.xml

This pom file includes as a dependency the JAX-WS artifact jar created above and uses the Maven Exec Plugin to activate the SOAP client.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" ... 

    <modelVersion>4.0.0</modelVersion>
    <artifactId>dev-guide-wsdl-first-client</artifactId>
    <name>-- SOAP Client</name>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.talend.cxf-examples.dev-guide-wsdl-first</groupId>
        <artifactId>dev-guide-wsdl-first</artifactId>
        <version>6.2.2</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.talend.cxf-examples.dev-guide-wsdl-first</groupId>
            <artifactId>dev-guide-wsdl-first-service</artifactId>
            <!-- Classifier below used with Maven Assembly Plugin to specify 
                subset of above artifact needed. -->
            <classifier>jaxws</classifier>
            <version>6.2.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>java</executable>
                    <arguments>
                        <argument>-classpath</argument>
                        <classpath />
                        <argument>
                            client.WSClient
                        </argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>