Blog‎ > ‎

Deploying a Maven archetype

I've just wasted many hours trying to figure out how to deploy a Maven archetype to our Maven repository, so perhaps this can save people some time.

The documentation for creating archetypes is not great, but it's OK. I highly recommend starting from a project and converting it to an archetype, rather than creating one from scratch.

I found this helpful article to walk me through the steps. There are many more if you Google around.

Once you can successfully create your archetype, you'll install it (mvn install) to your local repository (~/.m2), and you can use it to generate your app. Great. Now how do you deploy this bad boy to your Maven repository?

This is where the documentation leaves you completely up the creek. First for the actual deployment. We use ant for our builds, so here is the target to create and deploy the archetype:

<target name="uploadArchetypeToMaven" depends="checkoutSource">

<path id="maven-ant-tasks.classpath" path="${ThirdPartyHome}/apache-maven/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
classpathref="maven-ant-tasks.classpath" />
<artifact:install-provider artifactId="wagon-ftp" version="1.0-beta-2"/>
<artifact:pom id="mypom" file="${}/pom.xml" />

<artifact:mvn pom="${}/pom.xml">
   <arg value="package"/>

<artifact:deploy file="${}/target/demo-archetype-${build.version}.jar">
   <remoteRepository url="">
     <authentication username="john.doe" password="secret"/>
   <pom refid="mypom"/>

<myftp server="${upload_server}" userid="john.doe" password="secret" 
<fileset dir="${}/build">
<include name="archetype-catalog.xml" />

A few things to notice:
  1. the package command will create your archetype in the target directory (no surprise here)
  2. the deploy command will then FTP it to your Maven repository
  3. the last step is critical and poorly undocumented: you need to have a file called archetype-catalog.xml that lists the archetypes in your repository. This file looks like this for us:

<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog xsi:schemaLocation=""

It's supposed to be more or less automagically created for you, but I've found that taking control of it is the way to go (at least for us).

Once that's in place, you can instantiate your archetype with a command like this:

mvn archetype:generate \
    -DarchetypeGroupId=com.autobizlogic.abl \
    -DarchetypeArtifactId=demo-archetype \
    -DarchetypeVersion=2.1.4 \
    -DgroupId=com.acme \
    -DartifactId=demo \
    -Dversion=1.0-SNAPSHOT \

I'd say that's all there is to it, but it took me an embarrassingly long time to figure all this out, so I hope this saves you from the same frustration.