4 de mar. de 2011

Learn how to create a WebService Client using Maven and Axis

With Maven you can generate the client every time when the WSDL that defines theWeb services is modified.

We know that this is possible directly through Eclipse but ... Imagine if tomorrow youcan no longer use Eclipse ... "Now I have to use NetBeans ... And now?". Easy! We're talking about Maven... Maven works from the command line, it works in Eclipse and also works in NetBeans. Although they are different ways the result is always the same.
Researching the topic I found a very interesting plugin: maven-plugin-axistools. Visit http://mojo.codehaus.org/axistools-maven-plugin/index.html for more information about using this plugin.
To illustrate this possibility I will present a pom.xml configured to generate a client jar using the Amazon Web Service.
The first step is to download the wsdl in http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl.
Save this file in the folder src/main/resources/wsdl.
The next step is to create the pom.xml file below:
<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>org.maven3.tutorial</groupId>
<artifactId>amazon.ws.client</artifactId>
<version>1.0</version>
<name>Amazon WebServices Client</name>
<description></description>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>generate-project</id>
<goals>
<goal>wsdl2java</goal>
</goals>
<configuration>
<!--http://soap.amazon.com/schemas2/AmazonWebServices.wsdl -->
<sourceDirectory>src/main/resources/wsdl</sourceDirectory>
<outputDirectory>target/generated-sources</outputDirectory>
<packageSpace>org.maven3.tutorial</packageSpace>
<subPackageByFileName>true</subPackageByFileName>
<serverSide>true</serverSide>
<testCases>true</testCases>
<wrapArrays>true</wrapArrays>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</project>

Now is the easy part, run the command mvn package to generate the source code needed to access the Amazon Web Service.
Pesquisa personalizada

0 comentários:

Postar um comentário

Leia as regras:
Todos os comentários são lidos e moderados previamente.
Apenas os que respeitam as regras abaixo serão publicados:
- o comentário deve estar relacionado ao assunto do post
- não serão aceitos palavrões e ofensas ao redator do blog ou a terceiros
- não inclua links desnecessários no conteúdo do comentário
- se quiser deixar sua url, comente com a opção OpenId
Obs.: os comentários dos leitores não refletem a opnião do blog.