Home > Java, Maven3 > How to create a webservice client with Maven and JAX-WS

How to create a webservice client with Maven and JAX-WS

Maven allows you to integrate the generation of a JAX-WS webservice client into your build process. To do this, do the following:

1. Create a new module for the webservice client in your maven project.
2. Add the following configuration to the pom.xml of the new module:

<build>
 <plugins>
  <plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>jaxws-maven-plugin</artifactId>
   <version>1.10</version>
   <executions>
    <execution>
     <goals>
      <goal>wsimport</goal>
     </goals>
    </execution>
   </executions>
   <configuration>
    <packageName>nl.interact.ipds.agentvi.connector.schema</packageName>
    <wsdlUrls>
     <wsdlUrl>http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx?wsdl</wsdlUrl>
    </wsdlUrls>
    <extension>true</extension>
   </configuration>
  </plugin>
 </plugins>
</build>

<dependencies>
 <dependency>
  <groupId>com.sun.xml.ws</groupId>
  <artifactId>jaxws-tools</artifactId>
  <version>2.1.4</version>
 </dependency>
 <dependency>
  <groupId>org.jvnet</groupId>
  <artifactId>mimepull</artifactId>
  <version>1.3</version>
 </dependency>
</dependencies>

3. The jar that maven generates with the above config, can be used to write a client program like the following:

MovieInformation info = new MovieInformation();
ArrayOfTheater theaters = info.getMovieInformationSoap12().getTheatersAndMovies(“10001″, 1);
for (Theater t : theaters.getTheater()) {
  System.out.println(“Theatre: “+t.getName()+”, “+t.getAddress());
  ArrayOfMovie movies = t.getMovies();
  for (Movie m : movies.getMovie()) {
    System.out.println(” -”+m.getName()+”, (Rating: “+m.getRating()+”)”);
  }
}
About these ads
Categories: Java, Maven3 Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: