Question

I have a similar question to: this previous question

I am converting a Java project using Netbeans to Maven. In order to launch the program, one of the command-line arguments we need is the -javaagent setting. e.g.

-javaagent:lib/eclipselink.jar

I'm trying to get Netbeans to launch the application for development use (we will write custom launch scripts for final deployment)

Since I'm using Maven to manage the Eclipselink dependencies, I may not know the exact filename of the Eclipselink jar file. It may be something like eclipselink-2.1.1.jar based on the version I have configured in the pom.xml file.

How do I configure the exec-maven-plugin to pass the exact eclipselink filename to the command line argument?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <configuration>
       <executable>java</executable>
           <arguments>
               <argument>-Xmx1000m</argument>
               <argument>-javaagent:lib/eclipselink.jar</argument> <==== HELP?
               <argument>-classpath</argument>
               <classpath/>
               <argument>my.App</argument>
           </arguments>
    </configuration>
</plugin>
Was it helpful?

Solution

I figured out a way that seems to work well.

First, setup the maven-dependency-plugin to always run the "properties" goal.

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.5.1</version>
    <executions>
        <execution>
            <id>getClasspathFilenames</id>
            <goals>
                <goal>properties</goal>
            </goals>
        </execution>
     </executions>
</plugin>

Later on, use the property it sets as documented here with the form:

groupId:artifactId:type:[classifier]

e.g.

<argument>-javaagent:${mygroup:eclipselink:jar}</argument>

OTHER TIPS

Simply define a property for the eclipse link version and use the property in your <dependency> and the exec plugin:

    <properties>
        <eclipselink.version>2.4.0</eclipselink.version>
    </properties>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>${eclipselink.version}</version>
    </dependency>
    ...
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <configuration>
      <executable>java</executable>
       <arguments>
           <argument>-Xmx1000m</argument>
           <argument>-javaagent:lib/eclipselink-${eclipselink.version}.jar</argument>
           <argument>-classpath</argument>
           <classpath/>
           <argument>my.App</argument>
       </arguments>
     </configuration>
   </plugin>

the maven-dependency-plugin and exec-maven-plugin should be put under the node ,otherwise it will not work

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