Question

I want to pass parameters to file in archetype-resources>src>main folder. So I declared required property in archetype-metadata.xml as

<requiredProperties>
    <requiredProperty key="myParam">
      <defaultValue>default-value</defaultValue>
    </requiredProperty>
  </requiredProperties>

and used ${myParam} in prototype file, but its value is not replaced. Why?

If I use custom value in pom.xml of prototype project then resulting project replaces value of ${myParam} with myValue. It works fine but same does not work for file in prototype folder. why?

Was it helpful?

Solution

You need to tell the Velocity engine that your file should be used as Velocity templates (so that it will actually replace any properties that it finds in the file). You do this by extending your archetype-metadata.xml file and defining a fileSet.

I'm not sure of your exact folder structure and what the name of the file in question is, but something along these lines should work:

<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="basic">
    <requiredProperties>
        <requiredProperty key="myParam">
            <defaultValue>default-value</defaultValue>
        </requiredProperty>
    </requiredProperties>
    <fileSets>
        <fileSet filtered="true" packaged="false">
            <directory>src/main</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </fileSet>
    </fileSets>
</archetype-descriptor>

Basically the above is telling it to include all files under the src/main and the important part is filtered=true which will cause all properties to be replaced.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top