2013-02-08 44 views
10

javaagent的说法我有一个类似的问题:this previous question指定使用Maven Exec插件

我将使用NetBeans到Maven的Java项目。为了启动程序,我们需要的一个命令行参数是-javaagent设置。例如

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

回答

11

我想通了,似乎运作良好的方式。

首先,设置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] 

例如

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

太棒了!我只想指出,您需要将此元素放置在您的元素所在的pom.xml中。 (在我的例子中是)。让它在父pom.xml中似乎不起作用。再次感谢! – 2014-11-24 19:25:28

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

非常接近我终于选择了做。我想出了一种动态设置属性的方法,而不是对它进行硬编码。谢谢。 – 2013-02-08 17:46:40

+2

大卫,我有同样的问题,你可以请你分享你的解决方案,以解决这个问题? – PAcan 2013-03-15 12:29:07

0

maven的依赖性,插件和exec-Maven的插件应该节点下放,否则将无法正常工作