Update main class in pom when creating a project from an archetype

172 Views Asked by At

I'm working on an application leveraging Maven Archetypes. I've created an archetype and a project from it, but the main class reference in the pom file isn't getting updating, resulting in the generated project (which has different package names) referencing the main class of the original project. How can I update it during the generation of the derrivative project?

For example: If parent project has Application.class in package com.my_company.artifact_a, then in pom we have a ref for com.my_company.artifact_a.Application; when we generate the derivative with different group and artifact ids, meaning now the app is in let's say, com.your_company.artifact_b.Application, the reference in the pom file will still be for com.my_company.artifact_a.Application when I'd like it to be updated to the new info when we run maven archetype:create-from-project

1

There are 1 best solutions below

2
jordiburgos On

You can use the archetype variables in the source files of your archetype. The values of those variables will be interpolated in your generated source files.

File src/main/resources/archetype-resources/src/main/java/Application.java:

package ${package};

public class Application {
...
}

The package name will be set and the Application.java file will be put in the right folder for the specified package name.