javamavenmaven-archetype

Autogenerate packages (folders) and classes with maven archetype


I want to automatically generate some packages and some templates of classes in maven archetype, based on some parameters.

Let's say I have specified them as:

<archetype-descriptor name="basic">
    <requiredProperties>
        <requiredProperty key="package_name"/>
        <requiredProperty key="class_name"/>
    </requiredProperties>
</archetype-descriptor>

And I want to automatically create class based on some template in the folder /src/main/java/$package_name$:

The template can look like:

package $package_name$;

public class $class_name$ {
   // some predefined structure...
}

Is it whether possible to do or not?


Solution

  • Yes. This is supported feature.

    Check on this Baeldung post: Adding Required Resources