I am creating a custom maven archetype. I have defined the archetype.xml file under the src/main/resources/META-INF/maven. I also have included the default Java classes under the src/main/resources/archetype-resources/src/main/java. However I am not sure as to how can I parameterize the package names for the Java classes when the actual maven project gets generated. The basic maven guide to creating archetypes does not seem to have details around this. Any ideas as to how this can be done ?
Asked
Active
Viewed 379 times
3 Answers
1
Figured this out. You have to include the statement:
package ${packageName};
in the java classes. This ensures that the classess get generated with the right package information.

mithrandir
- 1,323
- 4
- 18
- 39
-
Are you sure of this ${packageName}? Just today have created an archetype and used ${package} instead, so I'm doubtful about another property name instead. I tested mine with interactive archetype generation. – LAFK 4Monica_banAI_modStrike Apr 10 '16 at 22:10
0
Hello you should specify you finalName. This can be done via this code in pom.xml Its described here : MAVEN also HERE you can fined some hints.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<finalName>YourNameOfJar</finalName>
</configuration>
</plugin>
-
Sorry maybe I wasn't clear enough, I was referring to java packages (as in java classes belonging to packages). How can this be specified in the .java files (located under src/main/resources/archetype-resources/src/main/java) ? – mithrandir Feb 18 '15 at 07:07
0
AFAIK you would need to call ${package} but you should not go too far with this, top level package is the limit.
So, having some subpackages, you would put all files in your top directory, and use
package ${package};
or
package ${package}.subpackage;
in them.
Have never created archetypes with more than top package though.

LAFK 4Monica_banAI_modStrike
- 2,840
- 35
- 53
-
Thats not correct. You can add subpackages in your top directory. The file in the subpackage has to be in the `src/main/java/subpackage/Yourclass.java` folder and needs this package declaration: `package ${package}.subpackage;` – Tobika Aug 31 '17 at 10:14
-
1Will test after vacation. I have a feeling back then it was like I described, but that's quite some time ago and it's just the feeling now. So, will check. Thanks. – LAFK 4Monica_banAI_modStrike Aug 31 '17 at 10:55