Search code examples
javaxmlmavenarchetypes

Adding property values to a maven archetype


Is it possible to add property values to a maven archetype so that these are requested on generation from a repository?

I'm trying to create an archetype from a project that contains strings such as ${mainUrl} in a config.xml file.

Im trying to set this up from the pom before i generate it. However the result is that that ${mainUrl} never changes. And attempts to set it via a properties file never succeed.


Solution

  • Ok , found a solution.

    I had to generate the archetype from my project with the required property added like this to the pom.xml

    <properties>
    <mainUrl>main-url</mainUrl>
    </properties>
    

    After generation using "mvn archetype:create-from-project"

    I added the xml below to archetype-metadata.xml

    <requiredProperties>
    <requiredProperty key="mainUrl"/>
    </requiredProperties>
    

    And to archetype.properties added "mainUrl=test"

    Then ran "mvn clean install" on the archetype.

    Now when i generate the archetype with "mvn archetype:generate -DarchetypeCatalog=local"

    It also prompts me to enter "mainUrl" and changes instances of ${mainUrl} to the url entered.