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
Hi There,
ReplyDeletei tried your example and i was getting an error as stated below.Can you let me know the java,eclipse version used?
Error:
-----------------------
The following mojo encountered an error while executing:
Group-Id: org.codehaus.mojo
Artifact-Id: jaxws-maven-plugin
Version: 1.12
Mojo: wsgen
brought in via: POM
Thanks
Siri
@Siri
ReplyDeleteI did this on an Apple MacBook Pro and used:
- Java 1.6.0_15
- Eclipse 3.5.0 (Build id: 20090621-0832)
Another way to quickly create webservices and get the XSD and WSDL starting from Java code is to use the Glassfish Tools Bundle for Eclipse (http://download.java.net/glassfish/eclipse/). This is a custom Eclipse that contains a complete Glassfish that allows you to use JAX-WS and deploy the classes directly to Glassfish and during that step the XSD and WSDL files are also created.
Hi,
ReplyDeleteThanks for the post.
The xml code is not showing correctly (no tags)
Can you please send me complete sample application with your classes and project files and directory?
I am looking for a maven 2 solution to generate the wsdl code and deploy my web services correctly on glassfish v3 from NetBeans 7. Seemed like the WS are ignored and having too many issues with it.
Thanks in advance.
G.
Seems like some upgrade for blogspot caused the syntax coloring plugin I use to stop working...
ReplyDeleteThis comment has been removed by the author.
ReplyDelete@Gadi to which email can I send the XML?
ReplyDelete