Importing Multiple WSDLs with Maven
The jax-ws-maven plugin for Maven includes the handy wsimport goal. This goal will take a WSDL from a URL or file and generate Java bindings for the service described. The generated code may not be beautiful, but it works. Anyway, today I spent more than an hour fiddling with wsimport. In my case I was trying to import multiple WSDLs into my project with different target packages. I ran into several hurdles and figured that I’d document them here for future victims.
First, for better or worse, I’m working in NetBeans. The Maven support is passable, but out of the box, the error reporting leaves a lot to be desired. In particular, detailed error reporting must be enabled. Otherwise, when there’s an error in your pom.xml file, you’ll get a nice <Badly formed Maven project> error with no other explanation. To enable error reporting go to Tools->Options->Miscellaneous->Maven, and check “Produce Exception Error Messages”. That will make your life easier. Now, about wsimport…
The obvious way to import multiple WSDLs is to include multiple executions in the jaxws-maven-plugin section of pom.xml. In fact, this is even the right way to do it… but if you just take your single-WSDL example, stolen from some tutorial somewhere, and copy it, you’ll end up with a couple of problems. First, when multiple execution are present, they must each be given a unique id, using of all things, the <id> tag. This wasn’t that tough to figure out once I turned on error reporting as described above.
The second issue was more problematic and, in my opinion, probably a bug in the plugin. Each execution includes a “staleFile” which is used to manage dependencies, i.e. correctly recompiling WSDL when it changes. However, it happens that when multiple executions are present they use the same staleFile. This means that the import of the second WSDL always thinks it’s up to date and thus never runs. After a bunch of googling, I managed to find a solution in this bug report. So, the solution is to manually set a staleFile for each WSDL. Here’s the resulting <plugin> block from pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>FirstWsdl</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlLocation>http://localhost:8080/FirstWsdl?wsdl</wsdlLocation>
<wsdlFiles>
<wsdlFile>path/to/FirstWsdl.wsdl</wsdlFile>
</wsdlFiles>
<packageName>com.example.first</packageName>
<!-- Without this, multiple WSDLs won't be processed :( -->
<staleFile>${project.build.directory}/jaxws/stale/wsdl.FirstWsdl.done</staleFile>
</configuration>
</execution>
<execution>
<id>SecondWsdl</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlLocation>http://localhost:8080/SecondWsdl?wsdl</wsdlLocation>
<wsdlFiles>
<wsdlFile>path/to/SecondWsdl.wsdl</wsdlFile>
</wsdlFiles>
<packageName>com.example.second</packageName>
<!-- Without this, multiple WSDLs won't be processed :( -->
<staleFile>${project.build.directory}/jaxws/stale/wsdl.SecondWsdl.done</staleFile>
</configuration>
</execution>
</executions>
</plugin>
That’s it. Cheers.
Dude, you totally aced it with your solution to this bug.
Apparently this guys *still* haven’t the bug (they upgraded to 1.12 version)
Thanks for the solution! Save me some major time. Much appreciated.
Excellent! Your description of the problem and solution worked perfectly. Awesome.
Great job.
Thanks for the solution. I do need multiply wsdl with different setting
Hats off to you for giving such excellent solution. I had been struggling with for two days. Now I got it and resolved my problems.
Thanks a ton again
Thanks a ton for blogging about it. Saved us a lot of hassle.
Cheers.
You really are making a difference by taking time to write this!. I am guilty of that. Inspiration for me to change@
Thank you Google for this site as the first match on “maven multiple wsimport executions”! Probably saved me hours of wasted time figuring this out. Thanks to you Dave I can go to bed before 1:00 am :-)
It saved quite a lot of time ! Thanks for this very useful post :)
Thank you for your post. It helped me to fix my bug.
This helped me as well.
One issue (not related to your excellent blog but to the plugin itself) is that when you have a project with a lot of WSDL files, you end up having quite a bit of executions. It would have been good if the plugin was able to nest the wsdlLocation within the wsdlFile element so we could have one execution block.
This same issue is present with the wsgen goal of this plugin as well when you specify the sei element. There was a bit of info that you could have seiList for multiple sei’s but that never seem to work for me.
Fantastic job, thank you!
very useful post. it helped me to save some hours today.
Thank you very much and Happy Christmas
Really Thanks man.
Thank you, i was not doing anything related to maven today just some reading….made my day today!
Dude u r just rocking.. I also tried lots of googling but i ws nt able to find correct solution.. The last para is just excellent..The problem was with using .. Thanks a lot
This 3 year old post is the gift that keeps on giving
Thanks a lot, you just saved me a lot of time. Keep it going..
Thanks. Helps better..
Me too. First link I clicked in Google, probably saved me an hour or more.