You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Brian Reath <bj...@gmail.com> on 2006/03/17 07:53:28 UTC

Package Naming In A Custom Maven 2 Archetype

Greetings -

I'm currently developing a custom Maven 2 archetype.  I'm running into a not
very important, but somewhat annoying, problem in that I cannot seem to get
package naming down.  I've got several source code .java files in the
src/main/resources/archetype-resources/src/main/java folder, and I would
like to set it up so that, when I use the archetype to generate a skeleton
directory structure, a few of these source objects go in a
${packageName}.dao package, a few others go in a ${packageName}.service
package, and the rest go in a ${packageName}.domain package.  The
${packageName} parameter will be specified from the command-line when
executing the archetype:create command.

For example, let's say I install my archetype and execute archetype:create
using my custom archetype to generate a project.  I'll add a command-line
parameter like "-DpackageName=org.blar.proj" when I do this.  I would like
this to create a project with three packages within the src/main/java
folder...one called org.blar.proj.dao, one called org.blar.proj.service, and
one called org.blar.proj.domain (replace the periods with slashes to get the
directory structure I would like to see), with the appropriate source files
in each package folder.

I have a package declaration as the first line of each source file in the
custom archetype, and I've been experimenting to see if I could get this to
work.  I've tried doing something like "package ${packageName}.dao;" as the
first line in my dao files, but this just causes the created directory
structure to have everything in a directory tree that corresponds to the
packageName parameter (under src/main/java, of course), without creating the
final dao folder (the same occurs for the files I would like to put into
service and domain packages).  I've also tried placing the source files in
the custom archetype in the
src/main/resources/archetype-resources/src/main/java folder within
subdirectories called dao, service, and domain, but this just causes the
generated projects to have a structure such as dao/org/blar/proj (using the
example packageName from above) under src/main/java, which is not the
desired effect. The package names within the actual source files are
resolving properly, it's just I can't seem to get the generated directory
structure to reflect the packages properly.

Does anyone have any idea how this can be done?

Thanks,
Brian Reath
bjreath@gmail.com