简体   繁体   中英

Create a maven archetype to generate multiple classes from one class template

I created a custom maven archetype that has a ClassName.java class that contains a property ${propertyName} with its getter and setter.

package ${package};

// Start of user code (import)

// End of user code (import)

/**
 * Block ${BlockName}
 */
public class ${BlockName} extends Block<${BlockName}DTO> {

    /**
     * Item  ${itemName}
     */
    private final Item<${itemType}> ${itemName} = new Item.Control<${itemType}>(this, "${itemName}") {

    };

    // Getter and Setter

}

What I want to achieve when creating a new project from this custom archetype is giving multiple class names (for example: Car, Bicycle ...), and give also multiple properties for each class (for example: Car.door, Car.window, Bicycle.wheel ...), and have as output the classes created from the template ClassName.java as Car.java and Bicycle.java, but in each class have the ${itemName}, getters and setters replaced with the properties given.

You can probably code a groovy script for that and run it post-generation

Is there a way to post-process project generated from archetype?

On the other hand: Generating getters/setters is standard IDE functionality (eg easily done in Eclipse), so I am not sure whether this is really useful in an archetype.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM