Hi, Thanks a lot, Kenney, for your explanation and code snippet! This is exactly what I was looking for! I have filled in the tiny missing details in your sample code to build up a working example which you can find below. Just in case anyone else is interested in it.
One thing I noticed is that the example should not be run from within a directory containing a pom.xml file since, otherwise, this project file is interpreted as being the parent model file! Well, again, thanks a lot! Regards, Ovidio ================================================================================ public class ProjectCreator { public static void main(String[] args) throws Exception { MavenEmbedder embedder = new MavenEmbedder(); embedder.setClassLoader( Thread.currentThread().getContextClassLoader() ); embedder.setLogger( new MavenEmbedderConsoleLogger() ); embedder.start(); Settings settings = embedder.buildSettings( embedder.getUserSettingsPath( null ), embedder.getGlobalSettingsPath(), false, false, false, Boolean.FALSE ); Properties properties = new Properties(); properties.put( "groupId", "net.sytes.meco" ); properties.put( "artifactId", "new_project" ); MavenExecutionRequest request = new DefaultMavenExecutionRequest() .setBasedir( new File( "/tmp" ) ) .setGoals( Arrays.asList( new String[] { "archetype:create" } ) ) .setLocalRepositoryPath( embedder.getLocalRepositoryPath( settings ) ) .setSettings( settings ) .setProperties( properties ) .addEventMonitor( new DefaultEventMonitor( new ConsoleLogger( ConsoleLogger.LEVEL_DISABLED, "logger" ) ) ); embedder.execute( request ); } } ================================================================================ Kenney Westerhof wrote: > On Sat, 27 May 2006, Ovidio Mallo wrote: > > Hi, > > Well, currently running archetype:create seems the simplest way to me. > The embedder is primarily meant to build projects, not to create them. > > You might want to take a look at the maven-cli project. Some plugins, like > archetype, don't require an existing pom.xml. > > A sequence like this (more or less) should work for you: > > MavenEmbedder embedder = new MavenEmbedder(); > > embedder.start(); > > Settings settings = embedder.buildSettings( > embedder.getUserSettingsPath( null ), > embedder.getGlobalSettingsPath(), > false, > false, > false, > false ); > > Properties properties = new Properties(); > // set archetype parameters in properties > > MavenExecutionRequest request = new DefaultMavenExecutionRequest() > .setBasedir(..) > .setGoals( Arrays.asList( new String[] { "archetype.create" } ) > .setLocalRepositoryPath( embedder.getLocalRepositoryPath( settings ) > .setSettings( settings ) > .setProperties( properties ); > > embedder.execute( request ); > > .. and we don't set a pom file here. > > Good luck! > > -- Kenney > > > >>Hi everyone! >> >>I just wanted to ask whether there is a clean way to create a new maven >>project using the MavenEmbedder API. It is of course possible to >>execute the "archetype:create" goal but the API seems to always >>require that you already pass in an existing project (at least >>an existing pom.xml file) in order to execute any goal. >>I think such a feature would be quite handy for other projects >>such as the Maven2 Eclipse Plugin. >> >>Thanks in advance for any help! >> >>Regards, >> Ovidio >> >>--------------------------------------------------------------------- >>To unsubscribe, e-mail: [EMAIL PROTECTED] >>For additional commands, e-mail: [EMAIL PROTECTED] >> > > > -- > Kenney Westerhof > http://www.neonics.com > GPG public key: http://www.gods.nl/~forge/kenneyw.key > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]