Home > java > Importing Multiple WSDLs with Maven

Importing Multiple WSDLs with Maven

March 11th, 2009 Leave a comment Go to comments

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:

            <!-- Without this, multiple WSDLs won't be processed :( -->
            <!-- Without this, multiple WSDLs won't be processed :( -->

That’s it. Cheers.

Categories: java Tags: , , ,
  1. asaf
    August 2nd, 2009 at 06:28 | #1

    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)

  2. Charl
    June 15th, 2010 at 10:31 | #2

    Thanks for the solution! Save me some major time. Much appreciated.

  3. Carlos
    August 4th, 2010 at 11:14 | #3

    Excellent! Your description of the problem and solution worked perfectly. Awesome.

  4. Sid
    October 25th, 2010 at 11:51 | #4

    Great job.

  5. leef
    December 17th, 2010 at 23:06 | #5

    Thanks for the solution. I do need multiply wsdl with different setting

  6. pramod
    February 4th, 2011 at 00:59 | #6

    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

  7. SS
    March 13th, 2011 at 10:08 | #7

    Thanks a ton for blogging about it. Saved us a lot of hassle.


  8. YOGA
    March 22nd, 2011 at 13:51 | #8

    You really are making a difference by taking time to write this!. I am guilty of that. Inspiration for me to change@

  9. August 29th, 2011 at 23:03 | #9

    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 :-)

  10. August 31st, 2011 at 00:06 | #10

    It saved quite a lot of time ! Thanks for this very useful post :)

  11. mehmet
    September 23rd, 2011 at 07:36 | #11

    Thank you for your post. It helped me to fix my bug.

  12. tkds
    November 5th, 2011 at 05:30 | #12

    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.

  13. Frater QL
    December 5th, 2011 at 13:47 | #13

    Fantastic job, thank you!

  14. Daya
    December 20th, 2011 at 13:22 | #14

    very useful post. it helped me to save some hours today.
    Thank you very much and Happy Christmas

  15. Ganeshkumar
    January 20th, 2012 at 15:06 | #15

    Really Thanks man.

  16. Dipesh
    March 22nd, 2012 at 00:31 | #16

    Thank you, i was not doing anything related to maven today just some reading….made my day today!

  17. Nitin Jagdale
    March 22nd, 2012 at 00:33 | #17

    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

  18. Paul
    May 1st, 2012 at 13:56 | #18

    This 3 year old post is the gift that keeps on giving

  19. Bharath
    July 3rd, 2012 at 15:35 | #19

    Thanks a lot, you just saved me a lot of time. Keep it going..

  20. Sundar
    December 3rd, 2012 at 08:20 | #20

    Thanks. Helps better..

  21. JVC
    March 2nd, 2013 at 18:06 | #21

    Me too. First link I clicked in Google, probably saved me an hour or more.

  22. Martin
    October 20th, 2015 at 06:34 | #22

    Even after 6 years, this is still applicable!

  1. No trackbacks yet.