Reputation: 22867
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?
Upvotes: 6
Views: 13607
Reputation: 3156
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>
Upvotes: 1
Reputation: 563
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>
Upvotes: 1
Reputation: 1802
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");
Upvotes: 2