2

I'm trying to generate Java code using locally stored group of wsdl's to avoid calling a remote server on runtime.

I want to be able to generate the code on a dev machine and run it on production, so I need the path to the wsdl on the generated code to be relative.

Using two plug-ins I've managed to either use a relative path or to mention a folder location, but I haven't manage to get both.

Using codehause I can use relative path but not to point to a folder:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>1.9</version>
    <executions>
        <execution>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <sourceDestDir>${project.build.directory}/generated-sources/jaxb</sourceDestDir>
                <wsdlDirectory>${basedir}/wsdl</wsdlDirectory>
                <wsdlLocation>../../../../../wsdl/*</wsdlLocation>
            </configuration>
        </execution>
    </executions>
</plugin>

This is the generated service:

    try {
        URL baseUrl;
        baseUrl = path.to.package.BarService.class.getResource(".");
        url = new URL(baseUrl, "../../../../../wsdl/*");
    } catch (MalformedURLException e) {
        logger.warning("Failed to create URL for the wsdl Location: '../../../../../wsdl/*', retrying as a local file");
        logger.warning(e.getMessage());
    }

The relative path is as expected, but the wsdle name appears as *, which cause the code to fail.

Using jax-ws-commons, I can point to a folder, but the relative path is gone (I tried also using classpath as in the commented line):

<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>
                <sourceDestDir>${project.build.directory}/generated-sources/jaxb</sourceDestDir>
                <wsdlDirectory>${basedir}/wsdl</wsdlDirectory>
                <wsdlLocation>../../../../../wsdl/*</wsdlLocation>
                <!--<wsdlLocation>classpath:wsdl/*</wsdlLocation>-->
            </configuration>
        </execution>
    </executions>
</plugin>

This is the generated service:

    try {
        url = new URL("file:/Users/username/Dev/company/project/wsdl/bar.wsdl");
    } catch (MalformedURLException ex) {
        e = new WebServiceException(ex);
    }

This will work on my machine but will fail on any other.

The generated code I wish for is:

    try {
        url = new URL("../../../../../wsdl/bar.wsdl");
    } catch (MalformedURLException ex) {
        e = new WebServiceException(ex);
    }
David Raviv
  • 397
  • 3
  • 10
  • I haven't found a solution to the issue. I would like to share the way I bypassed it. I used the org.jvnet.jax-ws-commons plugin and created a separate `` block for each wsdl. This works as long as the wsdl folder is defined as a resource. It is not an ideal solution as it forces me to maintain the pom for each new wsdl I add to the project. – David Raviv Mar 10 '14 at 06:31
  • See my answer here: http://stackoverflow.com/a/11579113/181336 – Adriaan Koster May 23 '14 at 14:19

0 Answers0