Home > Programming > Maven Archetypes and Required Properties

Maven Archetypes and Required Properties

While the src/main/resources/META-INF/maven/archetype-metadata.xml file has a section called requiredProperties, it doesn’t actually work unless a corresponding src/site/site.xml file exists in your archetype’s project. Weird but true fact. If you want to use custom properties (and I recommend that you do), go ahead and create that site.xml, even if it is just a skeleton.

I figured this out by accident when I was trying to fix the following error message produced by archetype:generate:

[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).

Project ID: unknown

Reason: Could not find the model file '/home/user/projects/test/newsubproject'. for project unknown

[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.reactor.MavenExecutionException: Could not find the model file '/home/user/projects/test/newsubproject'. for project unknown
at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:378)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:292)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.project.ProjectBuildingException: Could not find the model file '/home/user/projects/test/newsubproject'. for project unknown
at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1557)
at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:504)
at org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBuilder.java:198)
at org.apache.maven.DefaultMaven.getProject(DefaultMaven.java:583)
at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:461)
at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:534)
at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:365)
... 11 more
Caused by: java.io.FileNotFoundException: /home/user/projects/test/newsubproject (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:106)
at hidden.org.codehaus.plexus.util.xml.XmlReader.(XmlReader.java:123)
at hidden.org.codehaus.plexus.util.xml.XmlStreamReader.(XmlStreamReader.java:67)
at hidden.org.codehaus.plexus.util.ReaderFactory.newXmlReader(ReaderFactory.java:113)
at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1552)
... 17 more

Incidentally, the solution to that problem was to rename the pom.xml file in the directory I was executing the command in (/home/user/projects/test/pom.xml). Apparently it’s not possible generate a project inside another project. The error message is entirely unintuitive, but you probably expected that if you’re a Maven veteran.

So there are two quick, helpful Maven tips that I hope will help you as much as it helped me.

I should mention that I was helped by Antony Stubbs on Stack Overflow. He had responded to a post from Hardik Mehta, who also wrote about it on his cout blog. Thanks guys.

Categories: Programming Tags: ,
  1. 16 November, 2010 at 2:53 pm

    Actually, it is possible to generate a project inside another project when the site.xml file is present, or at least that’s the behavior I’ve been seeing. Unfortunately that also seems to lead to a conflict with properties such as ${rootArtfiactId}. I guess nothing is perfect, but this one was annoying when I accidentally discovered it.

  1. No trackbacks yet.

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: