Another day in Maven hell! I still don't get how something as simple as trying to get the JAX-WS tool wsgen to work can be this difficult.
My goal was to create a set of webservices starting from Java code and to then generate the necessary WSDL and XSD files. The first part, creating a domain model, annotating it with JAXB and then generating an XSD was simple enough. The second step kept me busy for the remaining 75% of the day.
I just added a new dependeny to my pom.xml and annotated my service with @WebService. But after triggering a recompile I got an error, the WebService annotation couldn't be found. Checked the pom.xml again, but it contained the correct dependency. So what was going wrong. Afer trying out some suggestions made in various blogs and forum posts, the problem remained. I even got to a point in which the code compiled, but when I executed the wsgen goal it would fail with the message: java.lang.NoClassDefFoundError: javax/jws/WebService. What? How can this be? By this time I was cursing away at Maven again: how can this bloody thing, that is supposed to make my life easier, always fuck up in the most incomprehensible way possible?
Then a little speck of light in the distance: it seems that the JAX-WS libraries are spread over a maven1 and a maven2 repository and that there are problems with some versions and references to other libraries that JAX-WS uses. The solution to all this:
The pom.xml I used:
My goal was to create a set of webservices starting from Java code and to then generate the necessary WSDL and XSD files. The first part, creating a domain model, annotating it with JAXB and then generating an XSD was simple enough. The second step kept me busy for the remaining 75% of the day.
I just added a new dependeny to my pom.xml and annotated my service with @WebService. But after triggering a recompile I got an error, the WebService annotation couldn't be found. Checked the pom.xml again, but it contained the correct dependency. So what was going wrong. Afer trying out some suggestions made in various blogs and forum posts, the problem remained. I even got to a point in which the code compiled, but when I executed the wsgen goal it would fail with the message: java.lang.NoClassDefFoundError: javax/jws/WebService. What? How can this be? By this time I was cursing away at Maven again: how can this bloody thing, that is supposed to make my life easier, always fuck up in the most incomprehensible way possible?
Then a little speck of light in the distance: it seems that the JAX-WS libraries are spread over a maven1 and a maven2 repository and that there are problems with some versions and references to other libraries that JAX-WS uses. The solution to all this:
- empty out your local repository
- add the java.net maven1 and maven2 repositories to your pom.xml
- add a dependency to JSR-181 to the wsgen plugin
The pom.xml I used:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
EDRL
Preprocessor
0.0.1-SNAPSHOT
com.sun.tools.jxc.maven2
maven-jaxb-schemagen-plugin
1.1
process-sources
${project.build.directory}/schemas
be/test/*.java
${basedir}/src/main/java
true
generate
org.codehaus.mojo
jaxws-maven-plugin
1.12
wsgen
generate-sources
be.test.service.TestService
true
true
true
javax.jws
jsr181-api
1.0-MR1
maven-repository.dev.java.net
Java.net Repository for Maven 1
http://download.java.net/maven/1/
legacy
maven2-repository.dev.java.net
Java.net Maven 2 Repository
http://download.java.net/maven/2
maven2-repository.dev.java.net
Java.net Maven 2 Repository
http://download.java.net/maven/2
javax.xml
jaxb-impl
2.1
javax.xml.bind
jaxb-api
2.2
com.sun.xml.ws
jaxws-rt
2.1.3
javax.jws
jsr181-api
1.0-MR1
1.5
1.5