You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Sagara Gunathunga <sa...@gmail.com> on 2009/02/24 10:47:52 UTC

How to execute Java task within a Archetype

Hi all

AFAIK when execute "archetype:create" command , the archetype copy the
 folder structure with resources  according to  the archetype's
archetype.xml file . I want to execute a custom Java method  in
addition to above default behaviour  along  with "archetype:create"
command . Is there any way to achieve this ....? if so please update
me with some references .



Thanks ,


Sagara Gunathunga

Blog - http://ssagara.blogspot.com
Web - http://sagaras.awardspace.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: How to execute Java task within a Archetype

Posted by Adam Leggett <ad...@upco.co.uk>.
If you do implement it as a plug-in then I'd suggest you create a
plug-in that does not require a pom so you can do

mvn archetype:create customplugin:goal -DartifactId= ...

You'll need '@requiresProject false' declared in your mojo impl javadoc.
I think the 'create' mojo is deprecated also. Maybe you should use
'generate 'instead.

-----Original Message-----
From: Sagara Gunathunga [mailto:sagaragu@gmail.com] 
Sent: 25 February 2009 09:48
To: Maven Users List
Subject: Re: How to execute Java task within a Archetype

Hi Adam,
Thanks again , I want to run a HTTP server within the generate goal
and then genarate some HTTPClient codes , these client codes depend on
the running HTTP server ,and not possible to package within the
archetype as templates.

I don't think hack the source code  is a good choice here ,  because
other people cant use my archetype with official  Maven2 distro , so
it seems like  post process the custom task in to  the new project's
scope is the only solution here . I will try to achieve this as a
plug-in .

Thanks ,

On Wed, Feb 25, 2009 at 2:23 PM, Adam Leggett <ad...@upco.co.uk>
wrote:
>
>> how can enforce Maven to execute custom task with " "mvn
>> archetype:generate "..?
>>
>
> generate is a goal of the archetype plug-in; AFAIK, you will need to
> either hack the source code of the archetype plug-in itself to execute
> some additional steps as part of the goal execution or post process
the
> generated project as indicated in my previous response.
>
> What exactly is your requirement here? What does your additional step
> need to do?
>
> --
> Adam Leggett
> BuildFactory Principal Architect
> UPCO
> Office: 0113 20 10 600
> Direct Line: 0113 20 10 631
> Mobile: 07801 269056
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
Sagara Gunathunga

Blog - ssagara.blogspot.com
Web - http://sagaras.awardspace.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to execute Java task within a Archetype

Posted by Sagara Gunathunga <sa...@gmail.com>.
Hi Adam,
Thanks again , I want to run a HTTP server within the generate goal
and then genarate some HTTPClient codes , these client codes depend on
the running HTTP server ,and not possible to package within the
archetype as templates.

I don't think hack the source code  is a good choice here ,  because
other people cant use my archetype with official  Maven2 distro , so
it seems like  post process the custom task in to  the new project's
scope is the only solution here . I will try to achieve this as a
plug-in .

Thanks ,

On Wed, Feb 25, 2009 at 2:23 PM, Adam Leggett <ad...@upco.co.uk> wrote:
>
>> how can enforce Maven to execute custom task with " "mvn
>> archetype:generate "..?
>>
>
> generate is a goal of the archetype plug-in; AFAIK, you will need to
> either hack the source code of the archetype plug-in itself to execute
> some additional steps as part of the goal execution or post process the
> generated project as indicated in my previous response.
>
> What exactly is your requirement here? What does your additional step
> need to do?
>
> --
> Adam Leggett
> BuildFactory Principal Architect
> UPCO
> Office: 0113 20 10 600
> Direct Line: 0113 20 10 631
> Mobile: 07801 269056
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
Sagara Gunathunga

Blog - ssagara.blogspot.com
Web - http://sagaras.awardspace.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to execute Java task within a Archetype

Posted by Adam Leggett <ad...@upco.co.uk>.
> how can enforce Maven to execute custom task with " "mvn
> archetype:generate "..?
> 

generate is a goal of the archetype plug-in; AFAIK, you will need to
either hack the source code of the archetype plug-in itself to execute
some additional steps as part of the goal execution or post process the
generated project as indicated in my previous response.

What exactly is your requirement here? What does your additional step
need to do?

-- 
Adam Leggett
BuildFactory Principal Architect
UPCO
Office: 0113 20 10 600
Direct Line: 0113 20 10 631
Mobile: 07801 269056

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to execute Java task within a Archetype

Posted by Sagara Gunathunga <sa...@gmail.com>.
HI all,
Adam , thanks for your comments , it seems like maven-antrun-plugin
could  use for this , but still I don't have exact idea  how can I use
it with my scenario, here I describe what I have done and what I
expect to do   in details

I create a Maven project to create a archetype called "myquickstart"
according to [1]   , this is the archetype.xml file for that.

<archetype>
  <id>myquickstart</id>
  <sources>
    <source>src/main/java/SimpleService.java</source>
  </sources>
  <testSources>
 <source>src/test/java/AppTest.java</source>
  </testSources>
   <resources>
        <resource>src/main/webapp/WEB-INF/web.xml</resource>
    </resources>
</archetype>


and this is the POM file for "myquickstart" project.

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>my</groupId>
  <artifactId>myquickstart</artifactId>
  <version>1.0.0</version>
  <description></description>
</project>


running "mvn install "  build and install myquickstart archetype in to
my local repo, then I can use "mvn archetype:generate
-DarchetypeGroupId=my -DarchetypeArtifactId=myquickstart
-DarchetypeVersion=1.0.0  "  to create a sample project successfully .


But this will copy source and resources files from archetype to new
project directory as I described in archetype.xml , what I expect to
do is , in addition to these things run a java method automatically
when I use  "mvn archetype:generate ........" command as above to
create new projects using myquickstart archetype.



I'm not sure   where I have to define Ant task ...? is it possible to
define such custom task within my  archetype.xml  file ...?
otherwise how can enforce Maven to execute custom task with " "mvn
archetype:generate "..?


Thanks ,


On Tue, Feb 24, 2009 at 10:59 PM, Adam Leggett <ad...@upco.co.uk> wrote:
> There are a number of ways to do this. A shell script is one option that
> springs to mind.
> For a simple 'pure' Maven approach that doesnt require you to write much
> code you could try something like this
>
> A pom (make sure you rename it to bootstrap.xml or some such) -
>
> <project>
>  <modelVersion>4.0.0</modelVersion>
>  <groupId>com.acme</groupId>
>  <artifactId>project-gen</artifactId>
>  <packaging>pom</packaging>
>  <version>1.0-SNAPSHOT</version>
>  <build>
>       <directory>${genArtifactId}</directory>
>       <plugins>
>        <plugin>
>        <artifactId>maven-antrun-plugin</artifactId>
>        <executions>
>          <execution>
>            <phase>process-resources</phase>
>            <goals>
>              <goal>run</goal>
>            </goals>
>            <configuration>
>                <tasks>
>                        <echo message="processing generated project ${genArtifactId} ..."/>
>                </tasks>
>            </configuration>
>          </execution>
>        </executions>
>      </plugin>
>      <plugin>
>        <artifactId>maven-archetype-plugin</artifactId>
>        <executions>
>          <execution>
>            <phase>generate-resources</phase>
>            <goals>
>              <goal>create</goal>
>            </goals>
>            <configuration>
>                <groupId>${genGroupId}</groupId>
>                <artifactId>${genArtifactId}</artifactId>
>            </configuration>
>          </execution>
>        </executions>
>      </plugin>
>    </plugins>
>  </build>
> </project>
>
> Combined with the following command line:
>
> mvn clean process-resources -DgenArtifactId=test-project
> -DgenGroupId=com.acme -f bootstrap.xml
>
> Should create you a basic quickstart project in a relative folder named
> [genArtifactId]
>
> You will need to invoke your Java 'method' via the antrun plugin.
>
> On Tue, 2009-02-24 at 14:49 +0100, Nick Stolwijk wrote:
>> First, the create goal has been deprecated, you can better use the
>> generate goal.
>>
>> Second, the documentation[1] says that it runs the "generate-sources"
>> before executing, so maybe it is possible to add your own plugin
>> there. Unfortunately, I don't know how it can be done and I can't find
>> any documentation or examples. Can someone more knowledgeable share
>> his insights?
>>
>> [1] http://maven.apache.org/plugins/maven-archetype-plugin/generate-mojo.html
>>
>> Hth,
>>
>> Nick Stolwijk
>> ~Java Developer~
>>
>> Iprofs BV.
>> Claus Sluterweg 125
>> 2012 WS Haarlem
>> www.iprofs.nl
>>
>>
>>
>> On Tue, Feb 24, 2009 at 10:47 AM, Sagara Gunathunga <sa...@gmail.com> wrote:
>> > Hi all
>> >
>> > AFAIK when execute "archetype:create" command , the archetype copy the
>> >  folder structure with resources  according to  the archetype's
>> > archetype.xml file . I want to execute a custom Java method  in
>> > addition to above default behaviour  along  with "archetype:create"
>> > command . Is there any way to achieve this ....? if so please update
>> > me with some references .
>> >
>> >
>> >
>> > Thanks ,
>> >
>> >
>> > Sagara Gunathunga
>> >
>> > Blog - http://ssagara.blogspot.com
>> > Web - http://sagaras.awardspace.com/
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> > For additional commands, e-mail: users-help@maven.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
> --
> Adam Leggett
> BuildFactory Principal Architect
> UPCO
> Office: 0113 20 10 600
> Direct Line: 0113 20 10 631
> Mobile: 07801 269056
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>



-- 
Sagara Gunathunga

Blog - ssagara.blogspot.com
Web - http://sagaras.awardspace.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to execute Java task within a Archetype

Posted by Adam Leggett <ad...@upco.co.uk>.
There are a number of ways to do this. A shell script is one option that
springs to mind. 
For a simple 'pure' Maven approach that doesnt require you to write much
code you could try something like this

A pom (make sure you rename it to bootstrap.xml or some such) - 

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.acme</groupId>
  <artifactId>project-gen</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <build>
       <directory>${genArtifactId}</directory>
       <plugins>
        <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
	    <phase>process-resources</phase>
            <goals>
              <goal>run</goal>
            </goals>
	    <configuration>
		<tasks>
			<echo message="processing generated project ${genArtifactId} ..."/>
		</tasks>
	    </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-archetype-plugin</artifactId>
        <executions>
          <execution>
	    <phase>generate-resources</phase>
            <goals>
              <goal>create</goal>
            </goals>
            <configuration>
		<groupId>${genGroupId}</groupId>
                <artifactId>${genArtifactId}</artifactId>
	    </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Combined with the following command line:

mvn clean process-resources -DgenArtifactId=test-project
-DgenGroupId=com.acme -f bootstrap.xml

Should create you a basic quickstart project in a relative folder named
[genArtifactId]

You will need to invoke your Java 'method' via the antrun plugin.

On Tue, 2009-02-24 at 14:49 +0100, Nick Stolwijk wrote:
> First, the create goal has been deprecated, you can better use the
> generate goal.
> 
> Second, the documentation[1] says that it runs the "generate-sources"
> before executing, so maybe it is possible to add your own plugin
> there. Unfortunately, I don't know how it can be done and I can't find
> any documentation or examples. Can someone more knowledgeable share
> his insights?
> 
> [1] http://maven.apache.org/plugins/maven-archetype-plugin/generate-mojo.html
> 
> Hth,
> 
> Nick Stolwijk
> ~Java Developer~
> 
> Iprofs BV.
> Claus Sluterweg 125
> 2012 WS Haarlem
> www.iprofs.nl
> 
> 
> 
> On Tue, Feb 24, 2009 at 10:47 AM, Sagara Gunathunga <sa...@gmail.com> wrote:
> > Hi all
> >
> > AFAIK when execute "archetype:create" command , the archetype copy the
> >  folder structure with resources  according to  the archetype's
> > archetype.xml file . I want to execute a custom Java method  in
> > addition to above default behaviour  along  with "archetype:create"
> > command . Is there any way to achieve this ....? if so please update
> > me with some references .
> >
> >
> >
> > Thanks ,
> >
> >
> > Sagara Gunathunga
> >
> > Blog - http://ssagara.blogspot.com
> > Web - http://sagaras.awardspace.com/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
-- 
Adam Leggett
BuildFactory Principal Architect
UPCO
Office: 0113 20 10 600
Direct Line: 0113 20 10 631
Mobile: 07801 269056

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How to execute Java task within a Archetype

Posted by Nick Stolwijk <ni...@gmail.com>.
First, the create goal has been deprecated, you can better use the
generate goal.

Second, the documentation[1] says that it runs the "generate-sources"
before executing, so maybe it is possible to add your own plugin
there. Unfortunately, I don't know how it can be done and I can't find
any documentation or examples. Can someone more knowledgeable share
his insights?

[1] http://maven.apache.org/plugins/maven-archetype-plugin/generate-mojo.html

Hth,

Nick Stolwijk
~Java Developer~

Iprofs BV.
Claus Sluterweg 125
2012 WS Haarlem
www.iprofs.nl



On Tue, Feb 24, 2009 at 10:47 AM, Sagara Gunathunga <sa...@gmail.com> wrote:
> Hi all
>
> AFAIK when execute "archetype:create" command , the archetype copy the
>  folder structure with resources  according to  the archetype's
> archetype.xml file . I want to execute a custom Java method  in
> addition to above default behaviour  along  with "archetype:create"
> command . Is there any way to achieve this ....? if so please update
> me with some references .
>
>
>
> Thanks ,
>
>
> Sagara Gunathunga
>
> Blog - http://ssagara.blogspot.com
> Web - http://sagaras.awardspace.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org