Creating an archetype from a project involves two steps:
At the end of these steps, you have a Maven 2 archetype created in the target/generated-sources/archetypeng directory.
It is possible to use the generation plugin in batch mode.
During this step, you are successivly prompted to:
A properety file containing the archetype definition and the archetype's properties is written at the end of this step.
The packageName property provides a default value of the guessed package of the project based on the packages of the project's sources.
During this step, the plugin creates a Maven 2 archetype based on the project's sources and pom and on the configuration collected.
To create an archetype, call mvn archetypeng:create-from-project.
[rafale@fixe test-start]$ tree
.
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- org
| `-- codehaus
| `-- mojo
| `-- archetypeng
| `-- test
| `-- start
| `-- App.java
`-- test
`-- java
`-- org
`-- codehaus
`-- mojo
`-- archetypeng
`-- test
`-- start
`-- AppTest.java
17 directories, 3 filesHere is a sample project (the one generated by the generation :-)).
[rafale@fixe test-start]$ mvn archetypeng:create-from-project [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetypeng'. [INFO] artifact org.codehaus.mojo:maven-archetypeng-plugin: checking for updates from central [INFO] ---------------------------------------------------------------------------- [INFO] Building test-start [INFO] task-segment: [archetypeng:create-from-project] [INFO] ---------------------------------------------------------------------------- [INFO] Preparing archetypeng:create-from-project
The first step of the creation: configure-creation
[INFO] [archetypeng:configure-creation] Define value for archetype.groupId: org.codehaus.mojo.archetypeng.test: : Define value for archetype.artifactId: test-start-archetype: : Define value for archetype.version: 1.0-SNAPSHOT: : Define value for groupId: org.codehaus.mojo.archetypeng.test: : Define value for artifactId: test-start: : Define value for version: 1.0-SNAPSHOT: :
Archetype definition (archetype.*) and common properties are defined using the proposed default values.
Add a new custom property Y: : Y Define property key: aProperty Define value for aProperty: : String searched in the sources Add a new custom property Y: : N
A custom property is added to the project creation.
Confirm archetype configuration: archetype.groupId: org.codehaus.mojo.archetypeng.test archetype.artifactId: test-start-archetype archetype.version: 1.0-SNAPSHOT package: org.codehaus.mojo.archetypeng.test.start version: 1.0-SNAPSHOT groupId: org.codehaus.mojo.archetypeng.test aProperty: String searched in the sources artifactId: test-start Y: : Y
The archetype configuration is confirmed.
[INFO] [archetypeng:create-archetype]
The second step do the work without any comment.
[INFO] [archetypeng:create-from-project] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 29 seconds [INFO] Finished at: Mon Mar 12 19:09:52 CET 2007 [INFO] Final Memory: 10M/24M [INFO] ------------------------------------------------------------------------
The resuting project is created in the target directory.
[rafale@fixe test-start]$ tree target/generated-sources/archetypeng
target/generated-sources/archetypeng
|-- pom.xml
`-- src
`-- main
`-- resources
|-- META-INF
| `-- maven
| `-- archetype.xml
`-- archetype-resources
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- App.java
`-- test
`-- java
`-- AppTest.java
11 directories, 5 filesTo enable the batch mode and remove the prompts, just run mvn archetypeng:create-from-project -B.
The batch mode wiil need the same answers as the interactive mode. These answers are provided in a property file named archetype.properties in the execution directory or set using the command line property -Darchetype.properties=path/to/archetype.properties.
Here is an example of archetype.properties file (the one generated by the interactive creation :-)).
[rafale@fixe test-start]$ cat archetype.properties # #Mon Mar 12 19:09:51 CET 2007 version=1.0-SNAPSHOT package=org.codehaus.mojo.archetypeng.test.start archetype.groupId=org.codehaus.mojo.archetypeng.test archetype.artifactId=test-start-archetype groupId=org.codehaus.mojo.archetypeng.test artifactId=test-start archetype.version=1.0-SNAPSHOT
Here is the plugin execution.
[rafale@fixe test-start]$ tree
.
|-- archetype.properties
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- org
| `-- codehaus
| `-- mojo
| `-- archetypeng
| `-- test
| `-- start
| `-- App.java
`-- test
`-- java
`-- org
`-- codehaus
`-- mojo
`-- archetypeng
`-- test
`-- start
`-- AppTest.java
17 directories, 4 filesEnsure the property file exists.
[rafale@fixe test-start]$ mvn archetypeng:create-from-project -B [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetypeng'. [INFO] artifact org.codehaus.mojo:maven-archetypeng-plugin: checking for updates from central [INFO] ---------------------------------------------------------------------------- [INFO] Building test-start [INFO] task-segment: [archetypeng:create-from-project] [INFO] ---------------------------------------------------------------------------- [INFO] Preparing archetypeng:create-from-project [INFO] [archetypeng:configure-creation] [INFO] [archetypeng:create-archetype] [INFO] [archetypeng:create-from-project] [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 16 seconds [INFO] Finished at: Mon Mar 12 19:13:22 CET 2007 [INFO] Final Memory: 10M/24M [INFO] ------------------------------------------------------------------------
The project tree is the same as in the interactive mode.