0

Here is a wsdl service link: http://www.webservicemart.com/uszip.asmx?WSDL

If I run the following command:

wsimport -s src -d bin http://www.webservicemart.com/uszip.asmx?WSDL

This command produces Java source code in the /src directory and compiled .class files in the /bin directory relative to the directory from which the command was issued. These generated classes can be used to access the remote web service.

Created a jar file, zipws.jar, containing the classes in the package com.webservicemart.ws by issuing the following commands:

  • cd /bin
  • jar cvf zipws.jar com

I can Add this jar into my build path in the java project and use it.

Is there a way I can have a java project created with maven2 and specify this wsdl url in POM.xml and have the jars directly downloaded into my local machine? Please let me know if you need more information.

Mike
  • 899
  • 9
  • 27
  • 45

1 Answers1

6

You can use the jaxws-maven-plugin:

<?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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.webservicemart.ws</groupId>
  <artifactId>uszip</artifactId>
  <version>1.0-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>jaxws-rt</artifactId>
      <version>2.2.8</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.jvnet.jax-ws-commons</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <goals>
              <goal>wsimport</goal>
            </goals>
            <configuration>
              <wsdlUrls>
                <wsdlUrl>http://www.webservicemart.com/uszip.asmx?WSDL</wsdlUrl>
              </wsdlUrls>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

The wsdlUrls parameter allows you to specify the location of the WSDL file. As with manually running wsimport the file is automatically downloaded when building the project.

  • Thanks for the reply. This downloads the .java files for me. Is there a way I can have only the jar file downloaded? – Mike Oct 20 '13 at 12:38
  • @Mike When you run `mvn clean package` maven downloads the wsdl, generates the .java source files, compiles them to class files and packages them into a .jar file. You will find the jar file in the target folder, it is called `uszip-1.0-SNAPSHOT.jar`. – Stefan Reuter Oct 20 '13 at 21:57
  • With this only .java source files is downloaded and compiled and stored in the target folder but not as a jar file .Is there a way I can have only the jar file downloaded(without source)? and also this would be generated in the target folder - can i change this directory else where(may be .m2/repository/{myfoldername}) – Mike Oct 21 '13 at 11:07
  • You can run `mvn install`, this will install the jar file in your local repository. In my example it will end up in `.m2/repository/com/webservicemart/ws/uszip/1.0-SNAPSHOT/uszip-1.0-SNAPSHOT.jar` – Stefan Reuter Oct 22 '13 at 12:32