Nino Martinez’s Weblog

TechBlog about Wicket, Persistence, IOC and Java

Making a Maven Archetype

So I want to create a maven archetype. My first run at this were a couple of months ago, it were pretty hard but then again I built the archetype from scratch.

I use userlist’s a lot so and though that it were very awkward how I did the previous archetype. So I wrote maven user list asking and theres actually a maven goal for it. So you can create an archetype in 6 steps:

  1. Build a project that will act as a template for the archetype
  2. run mvn archetype:create-from-project , from the project folder
  3. Edit the generated archetype ( placed in target/generated-sources/archetype ), it might not pickup on everything that needs to be substituted.
  4. From target/generated-sources/archetype of the project template run mvn install
  5. Try the archetype yourself by running mvn archetype:generate -DarchetypeCatalog=local from a fresh directory
  6. Repeat the process until satisfied

Now this also works for projects consistent of modules, a project structure like below:

Root
|-Core
|-Web

Happy Archetyping:)

September 3, 2008 - Posted by ninomartinez | JAVA, Maven | | 4 Comments

4 Comments »

  1. Hi Nino,

    Great tip here, thanks.

    I have encountered a couple of problems when trying to follow the steps above and I wonder if you have any pointers on how to resolve things.

    Firstly, when running mvn archetype:create-from-project I get the following error.

    [INFO] Cannot create archetype from this project.

    Embedded error: /home/emalethan/work/zzmalethan_blog/seemorej-hibernate-archetype-template/src/main/archetype/archetype.properties (No such file or directory)

    When I add this file (empty, btw) I get a much bigger error, as follows.

    …[INFO] [archetype:create-from-project]
    java.lang.NullPointerException
    at org.apache.oro.text.regex.Perl5Compiler.compile(Perl5Compiler.java:1954)
    at org.apache.maven.archetype.FilteringCopier.copy(FilteringCopier.java:83)
    at org.apache.maven.archetype.FileUtils.copyFile(FileUtils.java:797)
    at org.apache.maven.archetype.FileUtils.copyFileToDirectory(FileUtils.java:749)

    I can’t find much by Googling. I’d be grateful for any pointers?

    Cheers

    E

    Comment by Elwyn | January 17, 2009 | Reply

    • Hmm that’s a bit wierd, what kind of project are it, war / jar or?

      But notice that both problems are actually only INFO’s…

      Comment by ninomartinez | January 25, 2009 | Reply

  2. I got the same error, but resolved when using newer version of archetype plugin.

    try 2.0-alpha-4 of maven-archetype-plugin by specifying the version in pom.xml

    maven-archetype-plugin
    2.0-alpha-4

    Comment by Yang | February 24, 2009 | Reply

  3. [...] as per Nino Martinez’s tip I used mvn archetype:create-from-project to attempt to create an archetype from my example [...]

    Pingback by Maven Troubles | March 12, 2009 | Reply


Leave a comment