How do I create an archetype that can run on an existing project?
Author: Deron Eriksson
Description: This maven tutorial describes how to create an archetype that can run on a project that already exists.
Tutorial created using:
Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)
By default, an archetype cannot run on a project that already exists. However, it's possible to allow an archetype to run on a pre-existing project by adding an allowPartial element set to true in your archetype's archetype.xml file. As an example, here is an archetype project called "maven-archetype-bacon-and-eggs": The "maven-archetype-bacon-and-eggs" project's archetype.xml file is shown here. Notice that it contains an allowPartial element set to true. It also specifies two resources for the archetype, a bacon.txt file and an eggs.txt file. archetype.xml<archetype> <id>maven-archetype-bacon-and-eggs</id> <allowPartial>true</allowPartial> <resources> <resource>src/main/resources/bacon.txt</resource> <resource>src/main/resources/eggs.txt</resource> </resources> </archetype> This archetype project has a regular pom.xml file, included here for reference: pom.xml<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.myarchetype</groupId> <artifactId>maven-archetype-bacon-and-eggs</artifactId> <version>1.0-SNAPSHOT</version> <name>Archetype - maven-archetype-bacon-and-eggs</name> <url>http://maven.apache.org</url> </project> I'll build and install the archetype in my local mavenSW repository via "mvn clean install". Console output for 'mvn clean install' on 'maven-archetype-bacon-and-eggs' project[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Archetype - maven-archetype-bacon-and-eggs [INFO] task-segment: [clean, install] [INFO] ------------------------------------------------------------------------ [INFO] [clean:clean] [INFO] Deleting directory C:\dev\workspace\maven-archetype-bacon-and-eggs\target [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] No sources to compile [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] No sources to compile [INFO] [surefire:test] [INFO] No tests to run. [INFO] [jar:jar] [INFO] Building jar: C:\dev\workspace\maven-archetype-bacon-and-eggs\target\maven-archetype-bacon-and-eggs-1.0-SNAPSHOT.jar [INFO] [install:install] [INFO] Installing C:\dev\workspace\maven-archetype-bacon-and-eggs\target\maven-archetype-bacon-and-eggs-1.0-SNAPSHOT.jar to \dev\m2repo\com\myarchetype\maven-archetype-bacon-and-eggs\1.0-SNAPSHOT\maven-archetype-bacon-and-eggs-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Wed Feb 20 18:47:28 PST 2008 [INFO] Final Memory: 7M/13M [INFO] ------------------------------------------------------------------------ (Continued on page 2) |