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

3

6

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?

Dispraise answered 10/1, 2013 at 9:45 Comment(2)
meanwhile could you find a solution for the problem? I am facing the same problem as you and Samuels solution is really a ugly hack.Irreligion
Here is the same question with an alternative solution. #4164086Irreligion
P
2

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");
Poltroon answered 2/5, 2014 at 14:18 Comment(5)
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.Dispraise
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.Poltroon
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 :)Dispraise
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.Poltroon
sry but , definitely tried all .. the getClassLoader() never appeared , switched to cxf-codegen-plugin and all works fine .. #4455695Scyphate
A
1

For the generation of

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

This is the intended behavior, according to this,

https://www.mojohaus.org/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>
Aboveboard answered 31/1, 2013 at 9:51 Comment(1)
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...Dispraise
G
1

In my case, the generated file was missing the class.getClassLoader() part. Fixed it by adding forward-slash (/) before the name of the directory that resides in the resources directory, like this: <wsdlLocation>/wsdl/*</wsdlLocation>

Full configuration snippet:

<configuration>
  <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
  <wsdlLocation>/wsdl/*</wsdlLocation>
  <wsdlFiles>
    <wsdlFile>myFile.wsdl</wsdlFile>
  </wsdlFiles>
  <keep>true</keep>
</configuration>
Graeae answered 26/11, 2020 at 2:20 Comment(1)
Additional information here mojohaus.org/jaxws-maven-plugin/wsimport-mojo.html#wsdlLocationBryce

© 2022 - 2024 — McMap. All rights reserved.