Search code examples
variablesmavenlauncharchetypes

How to include a maven launch config in a maven archetype?


I got a liferay-portlet-project with a sample application/portlet that I want to become an archetype. Inside the project there is a folder containing two *.launch files to redeploy the webapp. Both have the following line which I have trouble with:

<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:/rawportlet}"/>

where "rawportlet" is the project's name. If I change it manually to ${artifactId} this variable is not resolved when using the archetype to create a project. Resolving this variable during project-generation would be nice.

Is there a way to achieve this? Or a workaround? Thanks in advance for your help.


Solution

  • Workaround: write a maven goal that the user can run after using the archetype. So the steps would be (for example):

    1. generate project from archetype

      mvn archetype:generate -DarchetypeCatalog=local

    2. do some post-generation cleanup (execute in project's base dir)

      mvn antrun:run

    So my code for this is in "pom.xml" in the archetype:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
            <execution>
                <id>default-cli</id>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <tasks>
                    <replace token= "rawportlet" value="${artifactId}" dir="runConfigs">                                 
                      <include name="**/*.launch"/>
                    </replace>
                  </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    The "runConfigs" directory is where the *.launch files are stored.

    Credits to:

    Full search and replace of strings in source files when copying resources

    Maven, configure specific goal