jaxws-maven-plugin resolving WSDL location relative to class location, why?

11,659

Solution 1

You should use jaxws-maven-plugin version 2.3 instead of 2.1 and the result will be as you would expected.

The output of version 2.3 like this (if your wsdl folder is under src/main/resources):

URL url = <Any>.class.getClassLoader().getResource("wsdl/anywsdl.wsdl");

Solution 2

For the generation of

url = new URL(baseUrl, "wsdl/mywsdl.wsdl");

This is the intended behavior, according to this,

http://jax-ws-commons.java.net/jaxws-maven-plugin/wsimport-mojo.html#wsdlLocation

It depends on what you want to do.

If what troubles you is

My_Service.class.getResource(".");

You can get rid of the point (relative path) with something like :

<plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>replacer</artifactId>
        <version>1.5.0</version>
        <executions>
          <execution>
            <phase>process-sources</phase>
            <goals>
              <goal>replace</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <file>target/generated-sources/wsimport/lu/hitec/webservices/pssu/${wsdl.app}/${interface.name}_Service.java</file>
          <replacements>
            <replacement>
              <token>_Service\.class\.getResource\("\."\)</token>
              <value>_Service\.class\.getResource\(""\)</value>
            </replacement>
          </replacements>
        </configuration>
      </plugin>
Share:
11,659
Danubian Sailor
Author by

Danubian Sailor

I prefer to be anonymouse.

Updated on June 04, 2022

Comments

  • Danubian Sailor
    Danubian Sailor almost 2 years

    I'm using the jaxws-maven-plugin version 2.1. I've found out very strange code generated for WSDL location from jar resources:

                    <configuration>
                        <keep>true</keep>
                        <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
                        <extension>true</extension>
                        <wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
                        <packageName>my.package.gen</packageName>
                        <wsdlLocation>wsdl/*</wsdlLocation>
                        <wsdlFiles>
                            <wsdlFile>mywsdl.wsdl</wsdlFile>                            
                        </wsdlFiles>
                    </configuration>
    

    And the code generated is:

    static {
        URL url = null;
        try {
            URL baseUrl;
            baseUrl = my.package.gen.My_Service.class.getResource(".");
            url = new URL(baseUrl, "wsdl/mywsdl.wsdl");
        } catch (MalformedURLException e) {
            logger.warning("Failed to create URL for the wsdl Location: 'wsdl/mywsdl.wsdl', retrying as a local file");
            logger.warning(e.getMessage());
        }
        MYSERVICE_WSDL_LOCATION = url; }
    

    So the wsdl file is looked up in the directory (package) the generated class residents, and not in the main jar directory, as would be logical. And the WSDL can't be found.

    Is it a bug in jaxws-maven-plugin, or it is the error in my configuration?

  • Danubian Sailor
    Danubian Sailor about 10 years
    You say it's fixed in version 2.3 of jaxws-maven-plugin? I've checked my company's Nexus and unfortunatelly the highest version is 2.2 (I can't use anything except artifacts from there). So I should suggest them to update version? Do you have any link to the issue with information, in which version was it fixed? I need something to prove such update is necessary.
  • Miklos Krivan
    Miklos Krivan about 10 years
    Yes that is true. I have changed only the version in my build from 2.3 back to 2.1 in order to see the result will be the same of @Łukasz웃Lツ . And that was it :-) I have checked also my gradle build with wsimport task which used jax-ws 2.1.4 and it was also wrong so I have updated to jax-ws 2.2.8 and the problem solved there as well. So JAX-WS tools 2.2.8 is also work as required.
  • Danubian Sailor
    Danubian Sailor about 10 years
    Yeah, a workaround, that requires using external library (plugin). I hope that is fixed in version 2.3 of jaxws-maven-plugin, as Miklos Krivan writes, in my case it will be hard to convince company to use newer version of jaxws plugin, convincing them to use a new plugin was practically impossible...
  • Danubian Sailor
    Danubian Sailor about 10 years
    I'll give that information to my company. If they update the plugin or fight that problem by hand fixing, it's up to them :)
  • Miklos Krivan
    Miklos Krivan about 10 years
    Now I have checked step by step the JAX-WS versions from 2.1.7 until 2.2.3 the difference is really visible :) The first change happend in 2.2 but it did not use the classloader just simple class.getResource() but already with the good relative path. The same in 2.2.1, 2.2.2 is missing. From 2.2.3 they use <Any>.class.getClassLoader().getResource("<path>") so what is the good one.
  • André
    André over 6 years
    sry but , definitely tried all .. the getClassLoader() never appeared , switched to cxf-codegen-plugin and all works fine .. stackoverflow.com/questions/4455195/…