14

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>
Community
  • 1
  • 1
David I.
  • 4,659
  • 3
  • 24
  • 33

3 Answers3

15

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>
David I.
  • 4,659
  • 3
  • 24
  • 33
  • Awesomeness! I would just point out that you need to put this element in the very pom.xml where your element resides. ( in my case)... I.e. having it in a parent pom.xml does not seem to work. Thanks again! – Jaroslav Záruba Nov 24 '14 at 19:25
3

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>
ben75
  • 27,769
  • 7
  • 80
  • 130
  • Very close to what I finally chose to do. I figured out a way to set a property dynamically instead of hard-coding it. Thanks. – David I. Feb 08 '13 at 17:46
  • 3
    David, I Have the same issue, can you please share your solution to this problem?? – PAcan Mar 15 '13 at 12:29
0

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

tearrain
  • 341
  • 3
  • 4