使用Maven exec插件指定javaagent参数

时间:2013-02-08 17:18:40

标签: maven javaagents

我有一个类似的问题:this previous question

我正在使用Netbeans将Java项目转换为Maven。为了启动程序,我们需要的命令行参数之一是-javaagent设置。 e.g。

-javaagent:lib/eclipselink.jar

我正在尝试让Netbeans启动应用程序以供开发使用(我们将编写自定义启动脚本以进行最终部署)

由于我使用Maven来管理Eclipselink依赖项,我可能不知道Eclipselink jar文件的确切文件名。它可能类似于eclipselink-2.1.1.jar,基于我在pom.xml文件中配置的版本。

如何配置exec-maven-plugin将精确的eclipselink文件名传递给命令行参数?

<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>

3 个答案:

答案 0 :(得分:14)

我想出了一种似乎运作良好的方式。

首先,设置maven-dependency-plugin以始终运行“属性”目标。

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

稍后,使用以下格式设置as documented here的属性:

groupId:artifactId:type:[classifier]

e.g。

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

答案 1 :(得分:2)

只需为eclipse链接版本定义一个属性,并使用<dependency>和exec插件中的属性:

    <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>

答案 2 :(得分:0)

maven-dependency-plugin和exec-maven-plugin应放在节点下,否则无法正常工作

相关问题