mercredi 13 octobre 2010

java : client webservice avec maven et jax-ws

Voici, le pom permettant de générer le code client via "wsimport"


<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>testJaxWS</groupId>
<artifactId>testJaxWS</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>testJaxWS</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

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

<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>

<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlUrls>
<wsdlUrl>
http://unServeur:20010/liaisons/services/Fourniture?wsdl

</wsdlUrl>
<!-- ${basedir}/src/main/resources/fourniture.wsdl -->
</wsdlUrls>
<packageName>com.proto.ws.fourniture</packageName> <!-- The name of your generated source package -->
</configuration>

<!--
if you want to use a specific version of JAX-WS, you can do so like

this

-->
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.1.3</version>
</dependency>
</dependencies>
</plugin>

<!-- Don't forget Java 5!! -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>



De plus, il est possible de générer la partie serveur avec wsgen :


<plugin>
<groupId>org.codehaus.mojo</groupId>

<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>

<goals>
<goal>wsgen</goal>
</goals>

<configuration>
<packageName>com.weflex.service</packageName>
<!-- The name of your generated source package -->
<sei>com.welflex.soap.ws.OrderWebService</sei>

<keep>true</keep>
<genWsdl>true</genWsdl>
</configuration>
</execution>

</executions>

Aucun commentaire:

Enregistrer un commentaire