2

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.

sotix
  • 822
  • 1
  • 8
  • 23

2 Answers2

1

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

Community
  • 1
  • 1
sotix
  • 822
  • 1
  • 8
  • 23
0

I have this same problem, and I used a different solution that works okay (but isn't perfect either).

Use value="${workspace_loc}/${artifactId}" in your launch config.

This will work as long as people do an archetype:gen at the workspace root. This works better for me than the selected answer because running that post processing requires another launch configuration (which somewhat defeats the whole purpose).

Ring
  • 2,249
  • 5
  • 27
  • 40