使用Maven exec插件指定javaagent参数 [英] Specify javaagent argument with Maven exec plugin

查看:624
本文介绍了使用Maven exec插件指定javaagent参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似的问题:上一个问题

I have a similar question to: this previous question

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

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

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

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

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

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.

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

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>

推荐答案

我想出了一种看起来不错的方法.

I figured out a way that seems to work well.

首先,将 maven-dependency-plugin 设置为始终运行属性"目标.

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]

例如

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

这篇关于使用Maven exec插件指定javaagent参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆