Maven - pass argument for use in exec-maven-plugin

In my pom, I added exec-maven-plugin to call the java class that will generate the file. This class requires that some parameters be passed to the main method, one of which is the location of the input file (outside the project). So far, I have used the relative path for this, which works fine:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>com.laco.projectmaster.util.LanguageGenerator</mainClass>
                <arguments>
                    <argument>../PM-Config/dev/PMLanguage.xls</argument>
                    <argument>PM4.0</argument>
                    <argument>${project.build.outputDirectory}/com/laco/projectmaster/props/resources</argument>
                    <argument>ProjectMaster</argument>
                    <argument>Created during maven build (POM Version: ${pom.version})</argument>
                </arguments>
            </configuration>
        </plugin>

Now I'm starting to use hudson to install / pack and deploy wars, and I can no longer use this relative path. I just thought I was just passing the location of the input file when calling maven as:

mvn net package -Dlangdir = C: / somedir

and then change the pom as:

<argument>${langdir}/PMLanguage.xls</argument>

. , , null/PMLanguage.xls. maven, antrun. .

, maven, , , pom?

,

+5
1

. :

package com.stackoverflow.q3421918;

public class Hello
{
    public static void main( String[] args )
    {
        System.out.println( args[0] + " " + args[1] );
    }
}

pom.xml:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.stackoverflow.q3421918</groupId>
  <artifactId>Q3421918</artifactId>
  <version>1.0-SNAPSHOT</version>

  <!-- this was a test for a workaround -->
  <properties>
    <myprop>${langdir}</myprop>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            <phase>test</phase>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>com.stackoverflow.q3421918.Hello</mainClass>
          <arguments>
            <argument>${myprop}</argument>
            <argument>${langdir}</argument>
          </arguments>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

, :

$ mvn clean package -Dlangdir=C:/somedir 
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3421918
[INFO]    task-segment: [clean, package]
[INFO] ------------------------------------------------------------------------
...
[INFO] Preparing exec:java
[WARNING] Removing: java from forked lifecycle, to prevent recursive invocation.
[INFO] No goals needed for project - skipping
[INFO] [exec:java {execution: default}]
Hello c:/somedir c:/somedir
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...

Maven 2.2.1.

+13

All Articles