-
Notifications
You must be signed in to change notification settings - Fork 3
Archetypes
Archetype helps authors create Maven project templates for users, and provides users with the means to generate parameterized versions of those project templates.
The easiest way to prepare archetype is to create it from existing and released project.
Checkout released SCM revision of existing project:
mvn scm:checkout '-DscmVersion=${project.artifactId}-0.0.3' -DscmVersionType=tag
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building simple-war-webapp 0.0.3-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-scm-plugin:1.4:checkout (default-cli) @ simple-war-webapp ---
[INFO] Removing C:\_data\projects\m4enterprise\trunk\simple-war\target\checkout
[INFO] Executing: cmd.exe /X /C "svn --non-interactive checkout http://m4enterprise.googlecode.com/svn/tags/simple-war-webapp-0.0.3 C:\_data\projects\m4enterprise\trunk\simple-war\target\checkout"
[INFO] Working directory: C:\_data\projects\m4enterprise\trunk\simple-war\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.166s
[INFO] Finished at: Tue Jan 18 11:03:31 CET 2011
[INFO] Final Memory: 7M/14M
[INFO] ------------------------------------------------------------------------
Released version is checked out into target\checkout
directory. Move to that directory and call archetype:create-from-project
to create archetype from existing project:
cd target/checkout/
mvn archetype:create-from-project
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building simple-war-webapp 0.0.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.0:create-from-project (default-cli) @ simple-war-webapp >>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven-version) @ simple-war-webapp ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-plugin-versions) @ simple-war-webapp ---
[INFO] The requirePluginVersions rule is currently not compatible with Maven3.
[INFO]
[INFO] <<< maven-archetype-plugin:2.0:create-from-project (default-cli) @ simple-war-webapp <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.0:create-from-project (default-cli) @ simple-war-webapp ---
[INFO] Setting default groupId: com.googlecode.m4enterprise
[INFO] Setting default artifactId: simple-war-webapp
[INFO] Setting default version: 0.0.3
[INFO] Setting default package: com.googlecode.m4enterprise
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building simple-war-webapp-archetype 0.0.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ simple-war-webapp-archetype ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 11 resources
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ simple-war-webapp-archetype ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-archetype-plugin:2.0:jar (default-jar) @ simple-war-webapp-archetype ---
[INFO]
[INFO] --- maven-archetype-plugin:2.0:add-archetype-metadata (default-add-archetype-metadata) @ simple-war-webapp-archetype ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.729s
[INFO] Finished at: Tue Jan 18 11:07:30 CET 2011
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------
[INFO] Archetype created in C:\_data\projects\m4enterprise\trunk\simple-war\target\checkout\target\generated-sources\archetype
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.245s
[INFO] Finished at: Tue Jan 18 11:07:30 CET 2011
[INFO] Final Memory: 10M/17M
[INFO] ------------------------------------------------------------------------
Archetype is generated into the target/generated-sources/archetype/
directory. Move to that directory and call deploy
goal to deploy archetype into repository:
cd target/generated-sources/archetype/
mvn deploy
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building simple-war-webapp-archetype 0.0.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ simple-war-webapp-archetype ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 11 resources
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ simple-war-webapp-archetype ---
[WARNING] Using platform encoding (Cp1250 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-archetype-plugin:2.0:jar (default-jar) @ simple-war-webapp-archetype ---
[INFO]
[INFO] --- maven-archetype-plugin:2.0:add-archetype-metadata (default-add-archetype-metadata) @ simple-war-webapp-archetype ---
[INFO]
[INFO] --- maven-archetype-plugin:2.0:integration-test (default-integration-test) @ simple-war-webapp-archetype ---
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ simple-war-webapp-archetype ---
[INFO] Installing C:\_data\projects\m4enterprise\trunk\simple-war\target\checkout\target\generated-sources\archetype\target\simple-war-webapp-archetype-0.0.3.jar to c:\_apps\apache-maven-repo\com\googlecode\m4enterprise\simple-war-webapp-archetype\0.0.3\simple-war-webapp-archetype-0.0.3.jar
[INFO] Installing C:\_data\projects\m4enterprise\trunk\simple-war\target\checkout\target\generated-sources\archetype\pom.xml to c:\_apps\apache-maven-repo\com\googlecode\m4enterprise\simple-war-webapp-archetype\0.0.3\simple-war-webapp-archetype-0.0.3.pom
[INFO]
[INFO] --- maven-archetype-plugin:2.0:update-local-catalog (default-update-local-catalog) @ simple-war-webapp-archetype ---
[INFO]
[INFO] --- maven-deploy-plugin:2.5:deploy (default-deploy) @ simple-war-webapp-archetype ---
Uploading: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/simple-war-webapp-archetype/0.0.3/simple-war-webapp-archetype-0.0.3.jar
Uploaded: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/simple-war-webapp-archetype/0.0.3/simple-war-webapp-archetype-0.0.3.jar (6 KB at 18.4 KB/sec)
Uploading: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/simple-war-webapp-archetype/0.0.3/simple-war-webapp-archetype-0.0.3.pom
Uploaded: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/simple-war-webapp-archetype/0.0.3/simple-war-webapp-archetype-0.0.3.pom (2 KB at 49.7 KB/sec)
Downloading: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/simple-war-webapp-archetype/maven-metadata.xml
Downloaded: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/simple-war-webapp-archetype/maven-metadata.xml (334 B at 10.5 KB/sec)
Downloading: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/maven-metadata.xml
Downloaded: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/maven-metadata.xml (271 B)
Uploading: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/simple-war-webapp-archetype/maven-metadata.xml
Uploaded: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/simple-war-webapp-archetype/maven-metadata.xml (334 B at 21.7 KB/sec)
Uploading: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/maven-metadata.xml
Uploaded: file:///c:\_data\repository\releases/com/googlecode/m4enterprise/maven-metadata.xml (271 B at 16.5 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.335s
[INFO] Finished at: Tue Jan 18 11:09:13 CET 2011
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------
Notice:
Archetype catalog is not uploaded into remote repository, please refer to the http://jira.codehaus.org/browse/ARCHETYPE-312. It must be uploaded manually.
Finally move to the fresh directory and create new project based on created archetype. Call archetype:generate
goal and provide the archetype GAV to eliminate manual selection from hundreds other archetypes.
mvn archetype:generate -DarchetypeGroupId=com.googlecode.m4enterprise -DarchetypeArtifactId=simple-war-webapp-archetype
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype [com.googlecode.m4enterprise:simple-war-webapp-archetype:0.0.3] found in catalog local
Define value for property 'groupId': : com.acme.foo
Define value for property 'artifactId': : foo
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': com.acme.foo: :
Confirm properties configuration:
groupId: com.acme.foo
artifactId: foo
version: 1.0-SNAPSHOT
package: com.acme.foo
Y: : Y
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.860s
[INFO] Finished at: Tue Jan 18 10:50:47 CET 2011
[INFO] Final Memory: 5M/10M
[INFO] ------------------------------------------------------------------------
Finally perform smoke test on created project:
cd foo/
mvn jetty:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building simple-war-webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-jetty-plugin:6.1.26:run (default-cli) @ foo >>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven-version) @ foo ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-plugin-versions) @ foo ---
[INFO] The requirePluginVersions rule is currently not compatible with Maven3.
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ foo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\_data\temp\_arch\foo\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ foo ---
[INFO] Compiling 2 source files to C:\_data\temp\_arch\foo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ foo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\_data\temp\_arch\foo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ foo ---
[INFO] Compiling 2 source files to C:\_data\temp\_arch\foo\target\test-classes
[INFO]
[INFO] <<< maven-jetty-plugin:6.1.26:run (default-cli) @ foo <<<
[INFO]
[INFO] --- maven-jetty-plugin:6.1.26:run (default-cli) @ foo ---
[INFO] Configuring Jetty for project: simple-war-webapp
[INFO] Webapp source directory = C:\_data\temp\_arch\foo\src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = C:\_data\temp\_arch\foo\target\classes
2011-01-18 10:52:58.324:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] Context path = /foo
[INFO] Tmp directory = determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = C:\_data\temp\_arch\foo\src\main\webapp\WEB-INF\web.xml
[INFO] Webapp directory = C:\_data\temp\_arch\foo\src\main\webapp
[INFO] Starting jetty 6.1.26 ...
2011-01-18 10:52:58.745:INFO::jetty-6.1.26
2011-01-18 10:52:59.073:INFO::No Transaction manager found - if your webapp requires one, please configure one.
2011-01-18 10:52:59.744:INFO::Started [email protected]:8080
[INFO] Started Jetty Server
Manual archetypes management is annoying. Archetype should be created, deployed and tested automatically by CI server.
Please refer to http://jira.codehaus.org/browse/ARCHETYPE-334 and http://maven.40175.n5.nabble.com/unit-testing-archetypes-td75257.html#a75257.