Maven Archetype dynamic package name

Viewed 447

Is it possible to have dynamic package name in maven archetype?? I want to have a dynamic package-name in the archetype(packagename == artifactId) and when I use this archetype for new project then the package name will be as the new artifactId.

Do anyone have idea about that??

1 Answers

I don't know if you found it in other places, so I'll leave here the form I use in my projects:

I use the variable ${groupId} within the classes:

package ${groupId}.service;

And within the archetype descriptor I add the attribute packaged as true.

<fileSet filtered="true" packaged="true">
<directory>src/main/java</directory>
<includes>
    <include>**/*.java</include>
</includes> 

Another alternative is to use the variable ${package}, as in the example below: https://howtodoinjava.com/maven/maven-custom-archetype/

Related