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:
- Build a project that will act as a template for the archetype
- run mvn archetype:create-from-project , from the project folder
- Edit the generated archetype ( placed in target/generated-sources/archetype ), it might not pickup on everything that needs to be substituted.
- From target/generated-sources/archetype of the project template run mvn install
- Try the archetype yourself by running mvn archetype:generate -DarchetypeCatalog=local from a fresh directory
- Repeat the process until satisfied
Now this also works for projects consistent of modules, a project structure like below:
Root |-Core |-Web
Happy Archetyping:)
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
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…
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
[...] 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 |