mtyson
mtyson

Reputation: 8560

Maven Archetype: Sub-package names

I am creating a maven archetype.

I know if I put my src/main/java/App.java class in there, I can get the package name with:

package $package;

But now I want to add a class like this: src/main/java/service/MyService.java

How do I inject the proper package in there?

$package

Gives me the root package. And $package.service just resolves as a literal.

Upvotes: 1

Views: 1011

Answers (2)

As @snovawinter proposed, use Maven property notation.

${x} means Maven property. You already noticed that Maven only works with root package here, and that's (I think) for a reason: archetypes ain't projects, they are project templates. By default: rather small - top level package is the limit.

So, having some subpackages: put all files in your top directory, and use

package ${package};

or

package ${package}.subpackage;

in them.

Upvotes: 0

snovawinter
snovawinter

Reputation: 29

You need to use

${package}.service

Upvotes: 2

Related Questions