Making a Maven Archetype

3 09 2008

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:)

Advertisements

Actions

Information

4 responses

17 01 2009
Elwyn

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

25 01 2009
ninomartinez

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…

24 02 2009
Yang

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

12 03 2009
Maven Troubles

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: