My work really consist in making different tools and java framework work together. I need to find solutions so that any developper can understand and use them afterwards.
This time the project involves developing lots of web services, and some batch treatments accessing to a single and complete business model. The business model is defined by an XSD file. This file will often change during the lifetime of the projet, so I need some automatic solutions. I decided to have a library containing the Java classes of the Business Model, and this library will be used by the web services and the batches. I’m using Maven, jaxb2 and jaxws, all under Netbeans, and I will explain how I managed to do that.
Generating jaxb2 beans using Maven:
First, I use the maven jaxb2 plugin to generate the corresponding Java Classes. Netbeans doesn’t support Jaxb2 mapping with Maven (only with ant), so I had to find and modify the pom.xml file manually. Once properly configured (with generated classes under target/generated-sources/xjc), the generated source code is automatically recognized by Netbeans (and greyed so that you know it’s generated, like in the screenshot below).
Creating the WebService:
Next, I create the .wsdl files, I’m not really expert in web services, so I create a web service using Netbeans (with the option to generate a wsdl from java classes), this was an easy way to get the .wsdl. Then I discard the other generated files from Netbeans, and told it to generate again the web service, this time using the .wsdl tweaked to import my Business Model .xsd.
The nice thing with Netbeans 6.7 and Maven, is that Netbeans modifies your maven project when you create a web service. The web service generation is really done by the maven project (using jax:ws plugin) and so is not dependent at all of Netbeans. Using other IDEs, you’ll have to create the web service using the wizards, and then manually modify the Maven project. Below is the modification made by Netbeans to the maven project file:
The problem:
When generating the Java source from the wsdl, the imported xsd is mapped again to Java classes. With the same files than the ones generated by Jaxb2. So I tried to tell the jaxws plugin that the .xsd file was already mapped. Documentation says you can use « episode » files, but this only works if the namespace of the webservice is different from the namespace of the XSD. That was not the case.
One solution is be to re-generate the source code, and delete the duplicated source so that only the classes in the business model project are used. That should work, but I need to keep some generated java classes: The ones from the Web Service itself. So I want to generate the .xsd classes in another package than the classes from the .wsdl (all with the same namespace !!)
The solution:
After lots of trials and errors, I eventually managed to do this by carefully crafting two files: one for jaxb and the other for jaxws, like this:
The content of bindings-jaxb.xml:
And the content of bindings-jaxw.xml:
I get the web service interface and factory generated in com.xxx.xxx.ws.mediation.service, and the source code from the business model in com.xxx.xxx.sas.data. It was then really easy to tell maven project to delete duplicates generated source code before compilation.
And as Netbeans compiles using maven, I get this behavior completely integrated into my IDE.
GC.





