14

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

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

-javaagent:lib/eclipselink.jar

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

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

如何配置 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>
4

3 回答 3

15

我想出了一个似乎运作良好的方法。

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

稍后,使用它设置的属性,如这里记录的形式:

groupId:artifactId:type:[classifier]

例如

<argument>-javaagent:${mygroup:eclipselink:jar}</argument>
于 2013-02-08T17:45:23.823 回答
3

只需为 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>
于 2013-02-08T17:30:16.413 回答
0

maven-dependency-plugin 和 exec-maven-plugin 应该放在节点下,否则不起作用

于 2017-02-28T07:40:19.330 回答