Reputation: 701
How are the package names determined while creating a project from a Maven archetype?
I figured out that it's composed by the groupId given while creating the project + the path in the archetype after src/main/java. (Correct me if I'm wrong)
Example:
Archetype folder tree src/main/java/service with groupId it.foo.stub creates the package it.foo.stub.service
For just a package I'd like to change the first part of the package name to something like it.bar.mock.business, but until now I haven't been able to find out how to. Is it even possible?
Upvotes: 7
Views: 4684
Reputation: 11699
You can create any package that you want. The package is mostly defined by the directory anyway. In your archetype-metadata.xml
file you can configure your archetype to generate any directories you want. This shows how to create two different packages in generated projects:
<fileSets>
<!-- Create a package using the groupId -->
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/java/__packageInPathFormat__</directory>
</fileSet>
<!-- Create a fixed package: it.bar.mock.business -->
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/java/it/bar/mock/business</directory>
</fileSet>
</fileSets>
This assumes you are using Maven Archetype 2.x.
Upvotes: 12