Maven note: exec-maven-plugin

I'm currently working on a development package containing a series of .xsd files which will be used to define the external interface for our web service. Due to some other project constraints, it was decided that this package also needed to include the .wsdl files which will further define the web service.

I'm a lazy (the good kind) programmer, so I decided that I did not want to update these files every time the schema changed nor did I want to make anyone else figure it out later. I wrote a quick utility for creating the .wsdl files, based on the current .xsd files. Since we're already expecting to use Spring-WS for message dispatching, I wrote some file generation code around the org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition class and wrote up a Spring configuration which put it all together.

My next task was to figure out a way to get this utility to run within the context of the Maven package phase. Since the code needed to generate the .wsdl files was the only code in this development package, it made sense to hook into the prepare-package phase instead of the generate-sources phase. Now that I knew when the utility should run, I just needed to figure out a way to do it. One Google search later, and I had the exec-maven-plugin. This Maven plugin provides two goals which can be hooked into arbitrary phases in the Maven life cycle:

  • exec -- execute an arbitrary executable from within the Maven runtime
  • java -- execute the main method, with arguments, of a specified class, from within the Maven runtime

So I set up my pom as shown below, and ran mvn package. The end result was a .jar file which contained both the .xsd and the .wsdl files we need. One mvn deploy later and these files were now available to all who needed them.



PhotoGeek said...

Thanks for the update - I am trying to do exactly that as well and this is pointing me in the right direction.

If I may ask - have you come across something something similar. I received an XSD and with JAXB generated the 282 Java classes, but these classes must be persisted into a DB (using JDO) when we unmarshal the XML files. That's the rule...

Currently I have written a small Java class to add @PersistenceCapable to the required generated classes. So "exec-maven" will greatly assist me in automating the process, as the XSD would probably change only once every 2 years.

I wrote the Java class because I can not seem to get annox-maven / hyperjaxb3 or datanucleus to help me out, meaning make the generated classes JDO persistent? Ideas?

Ryan David Ransford said...

Sorry, I'm unfamiliar adding annotations to classes pre-compile-time. To me, your annotation scheme sounds quite edge-case and will likely not rate a maven plugin. (a quick Google search seems to confirm this)

If you already have a class which does what you need, this should be the best way I know to integrate it with the maven build process.

Not knowing the rest of your application, would it be correct to assume that generating wrapper classes for the xjc-generated classes is impossible? That would be my ideal solution, I don't like to touch anything which is generated.