Monday, March 1, 2010

Maven plugin for JAXWS tools

JBossWS comes with JAXWS tools for top-down and bottom-up webservice development.

Starting from today, a Maven plugin is available for easily embedding tools' invocation into your own project's pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.jboss.ws.plugins</groupId>
<artifactId>maven-jaxws-tools-plugin</artifactId>
<version>1.0.0.GA</version>
<configuration>
<wsdls>
<wsdl>${basedir}/test.wsdl</wsdl>
<wsdl>${basedir}/test2.wsdl</wsdl>
</wsdls>
<targetPackage>foo.bar</targetPackage>
<extension>true</extension>
</configuration>
<executions>
<execution>
<goals>
<goal>wsconsume</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

this makes wsconsume parse the specified wsdl files and generate java sources for the SEI, wrapper, etc. The classes are then compiled together with all the other ones in your project.

Similarly you can use wsprovide, see the example below:
<build>
<plugins>
<plugin>
<groupId>org.jboss.ws.plugins</groupId>
<artifactId>maven-jaxws-tools-plugin</artifactId>
<version>1.0.0.GA</version>
<configuration>
<verbose>true</verbose>
<endpointClass>org.jboss.test.ws.plugins.tools.wsprovide.TestEndpoint</endpointClass>
<generateWsdl>true</generateWsdl>
</configuration>
<executions>
<execution>
<goals>
<goal>wsprovide</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>


The plugin has sensible defaults, in particular for computing the classpath to be used before invoking the tools; you just need to make sure your project declares dependencies on a jbossws stack (which you most probably already do, if you have ws endpoints there).
So it's really just a matter of declaring the plugin in the pom.xml and running ;-)
All stacks (JBossWS-Native, JBossWS-CXF, JBossWS-Metro) are supported by the plugin.
A couple of additional complete sample pom.xml files are available on the SCM, for instance take a look at this.
Enjoy!

10 comments:

Вячеслав said...

Didn't work with default settings on Jboss 4.2.2. Started working only when I added following dependencies to the plugin configuration:
org.jboss.ws jbossws-common 1.0.8.GA test org.jboss.ws.native
jbossws-native-client 3.0.5.GA
provided



Another problem: didn't work just by entering mvn wsconsume, but only this way: mvn org.jboss.ws.plugins:maven-jaxws-tools-plugin:1.0.0.GA:wsconsume

Third problem: generated only Java sources into folder "target/wsconsume/java". I expected to see jar file there instead...

It would be nice if you can provide some working examples about how to use this plugin...

Alessio Soldano said...

Hi,
thanks for giving the plugin a try!
Regarding JBoss AS 4.2.2, that's not supported any more. Currently, I suggest you using at least JBoss AS 5. See here http://community.jboss.org/wiki/JBossWS-SupportedTargetContainers .
Generally speaking, in any case, you need to have your pom provide dependency on a jbossws client artifacts, take a look at the examples included in the plugin: http://anonsvn.jboss.org/repos/jbossws/projects/plugins/maven/jaxws-tools/tags/jaxws-tools-1.0.0.GA/src/test/resources/test-embedded/testWsConsume/pom.xml

Regarding the way to run the plugin, that depends on how you setup your local maven environment. Try adding
<pluginGroups>
<pluginGroup>org.jboss.maven.plugins</pluginGroup>
<pluginGroup>org.jboss.ws.plugins</pluginGroup>
</pluginGroups>
to your settings.xml. You should then be able to do "mvn jaxws-tools:wsconsume". Otherwise, simply add the plugin to your pom's lifecycle as in the example.

Finally, as mentioned above, the sources come with working sample for JBossWS Native, CXF and Metro stacks.

Alexandru said...

On
JAVA_HOME=..../jdk_1.5

the plugin crash with the following error:

Internal error in the plugin manager executing goal.
...
Bad version number in .class file.

I looked into the plugin jar and it seems that it has been compiled with 1.6.

There is a reason for that? Where I can find the version compiled with 1.5?

Thanks

Alessio Soldano said...

Alexandru,
well, yes, the plugin has been compiled with JDK 1.6, as 1.5 is in end-of-life phase.

John said...

I tried this today. No success.

First, the plugin has dependencies on artifacts that are available only in jboss deprecated maven repostitory (apache-xerces:xercesImpl and wutka-dtdparser:dtdparser121) (see http://community.jboss.org/wiki/MavenGettingStarted-Users) The artifacts appear in maven central with different group and artifact ids (xerces:xercesImpl, com.wutka:dtdparser)

Then, after I replaces these with maven central based artifacts, I had to chase down several other runtime dependencies: org.jboss.jbossws:jbossws-native-core, com.sun.xml.ws:jaxws-tools, wstx:wstx)

Now, wsconsume is running, BUT, there is an error I cannot understand: "Unrecognized property 'org.codehaus.stax2.internNsUris'" I do no know where to go from here. I think I took a wrong turn.

Alessio Soldano said...

Hi Jon,
thanks for the feedback. I've just deployed a new 1.0.1-SNAPSHOT of the plugin. That basically removes the test scope dependencies to the jbossws stacks as well as the jbossxb one (which is was was pulling in artifacts from the deprecated repo). So those should not get in the way in your build anymore.
I'm currently targetting a new release for the plugin together with the JBossWS 3.4.0 next month.

Alessio Soldano said...

For the records, the new 1.0.1.GA version is available:

http://anonsvn.jboss.org/repos/jbossws/projects/plugins/maven/jaxws-tools/tags/jaxws-tools-1.0.1.GA/

https://repository.jboss.org/nexus/content/groups/public/org/jboss/ws/plugins/maven-jaxws-tools-plugin/1.0.1.GA/

sTiVo said...

the 1.0.1GA plugin is failing:

[ERROR] Failed to execute goal org.jboss.ws.plugins:maven-jaxws-tools-plugin:1.0.1.GA:wsconsume (default) on project relayws: Error while running wsconsume: org.jboss.wsf.spi.tools.WSContractConsumer -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jboss.ws.plugins:maven-jaxws-tools-plugin:1.0.1.GA:wsconsume (default) on project relayws: Error while running wsconsume
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error while running wsconsume
at org.jboss.ws.plugins.tools.AbstractWsConsumeMojo.execute(AbstractWsConsumeMojo.java:157)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: java.lang.ClassNotFoundException: org.jboss.wsf.spi.tools.WSContractConsumer
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.jboss.ws.plugins.tools.WSContractDelegate.runConsumerInProcess(WSContractDelegate.java:110)
at org.jboss.ws.plugins.tools.WSContractDelegate.runConsumer(WSContractDelegate.java:103)
at org.jboss.ws.plugins.tools.AbstractWsConsumeMojo.execute(AbstractWsConsumeMojo.java:149)
... 21 more

Jason said...

I am finding that the classloading for this plugin is deplorable. Is there a working example of this plugin that maps out the dependencies that I can reference?

Alessio Soldano said...

@Jason,
the plugin sources come with some tests you can have a look. Soon when updating the plugin for running with JBossWS 4.x and AS7, I'll see if I can produce some additional samples.