Wednesday, April 11, 2007

Using XDoclet with Maven 2

One of the useful features of Ant is ability to generate different kind of config files (and othe stuff) with the help of XDoclet. I would like to use this feature with Maven. It's take a lot of time to understand how to do the trick but for now it is working as expected and I want to share with you some of hints.
So, what is doing here. I just want to build servlet with Maven, generate deployment descriptor from annotated source and finally create a war file. OK, lets start.
First of all I'm creating a new Maven project like thins :

mvn archetype:create

In my pom.xml I have
so, all is ok. Final name of war file will be longRunningServlet.war. Further more interesting. Where I should place servlet source code ? Answer is longRunningServlet\src\main\java. But you should to create "java" directory by hand since it is not created by Maven. Is it bug of feature ? :) How we have directory strucure for building project with sources placed at longRunningServlet\src\main\java. To build servlet we need to set up dependencies. Standalone servlet has one dependency
Please notice scope=provided. In practice it is means that servlet api jar will not be placed in war's WEB-INF\lib.
And now XDoclet. Dependencies for XDoclet are :
Actualy XDoclet is executed via Maven Antrun plugin with specific configuration of both - maven-run plugin and xdoclet. Looks impressively :

<taskdef name="webdoclet"
classpathref="maven.compile.classpath" />

includes="**/*.java" />
Webdoclet configuration in between "tasks" tag. You can place any Ant task here but in my case it is XDoclet call.


Anonymous said...

You saved my life... thank you very much!

Stas Ostapenko said...

I'm glad to hear that :) Thanks for comment !