Specify javaagent argument with Maven exec plugin

前端 未结 3 703
太阳男子
太阳男子 2020-12-14 21:00

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

相关标签:
3条回答
  • 2020-12-14 21:17

    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>
    
    0 讨论(0)
  • 2020-12-14 21:22

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

    0 讨论(0)
  • 2020-12-14 21:32

    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>
    
    0 讨论(0)
提交回复
热议问题