Maven p13: Creating an archetype

An archetype in maven 3.0 is a shortcut for creating a certain directory structure, default files and pom. Android, for example, has its own archetype.

First create a project with this pom:

	<?xml version="1.0" encoding="UTF-8"?>
	<project xmlns="" xmlns:xsi="
	2001/XMLSchema-instance" xsi:schemaLocation=" h

We're creating a normal looking pom, but the packaging type is maven-archetype. The plugin grabs that type. And the extension make an artifact during the lifecycle. In this case for our archetype packaing.

Then in src/main/resources/META-INF/maven/archetype-metadata.xml you should talk about the layout of your archetype:

	<?xml version="1.0" encoding="UTF-8"?>
	<archetype-descriptor xsi:schemaLocation="" name="another_test"
	                <fileSet filtered="true">

It's saying there is a file, with a directory, which includes txt files. You can place an actual txt file in this directory, and it will appear when someone goes to create your archetype.

Now you need to mvn install that then run this command, from a non maven project directory to create a new project of your archetype:

	mvn archetype:generate \
	    -DarchetypeGroupId=org.denevell.mavenplugins       \
	    -DarchetypeArtifactId=newarche   \
	    -DarchetypeVersion=1.0-SNAPSHOT            \
	    -DgroupId=org.denevell.testyarchetype \

So we're specifying the group of the archetype we just created, along with its artifact id, and the version. Then we're giving it our own group and artifact name.


Edit on github
comments powered by Disqus
Click me