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);
}