views:

42

answers:

2

Hi all,

I am creating a new maven project from an eclipse plugin. As it seems to me a bad idea to hardcode pom.xml to my plugin. Is there any way to generate this programmatically such that the plugin will be more maintainable ?

Also creating the maven project structure from the plugin on my own seems to be a bad idea too ! Is there any api to do this tast ? (creating a maven project, adding my dependency to it)

What I am currently doing is to create folders, write a .classpath file (hardcoded) , injecting maven nature to .project file and now trying to generate the pom.xml. Seeing a pom.xml I thought writing one plugin for th ecurrent version of maven won't do a good job.

A: 

Sounds like you are trying to do the job of maven archetypes

mvn eclipse:eclipse
Michael Rutherfurd
Not exactly ! if so I will be creating an archtype each and everytime the plugin is called.
NS Gopikrishnan
You could check if the appropriate structure is present and if not execute mvn. Apparently you can create your own archetypes as well. Maybe that is the way to go... Create custom archetype, plugin creates new project by plugging user supplied detail into archetype call
Michael Rutherfurd
How will the plugin know that my archtype is present at the client ? Or did you mean to add the archtype first and then make the plugin call it for creating the project ?
NS Gopikrishnan
@NS Gopikrishnan: The archetype creates the project structure you've told it to. You could check if the archetype has been run by looking for something unique to your project structure e.g. pom.xml and your customised .classpath perhaps. I think the best way is to tie the mvn archetype command into new project creation.
Michael Rutherfurd
A: 

Not sure what you want/need to do exactly but you could maybe use the MavenXpp3Writer#write() method from the Maven Model API to write a POM from a given Model.

Pascal Thivent