Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify javaagent argument with Maven exec plugin

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>
like image 953
David I. Avatar asked Feb 08 '13 17:02

David I.


2 Answers

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>
like image 176
David I. Avatar answered Nov 15 '22 08:11

David I.


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>
like image 23
ben75 Avatar answered Nov 15 '22 09:11

ben75