gpt4 book ai didi

maven - 将命令行参数添加到 maven exec 插件

转载 作者:行者123 更新时间:2023-12-04 19:53:38 26 4
gpt4 key购买 nike

我正在尝试使用 exec:exec 目标使用 maven exec 插件运行 java 程序。
我需要向类路径(太阳工具 jar)添加一个额外的 jar。
由于 includePluginDependencies 仅适用于 exec:java 目标,我想在参数部分手动添加它,但找不到将它连接到基类路径的方法。问题是,由于 jar 被定义为系统范围,maven 不会将它添加到运行时类路径,我需要手动添加它。
如果有人知道如何从命令行执行此操作,那就更好了。
提前致谢,
阿夫纳

  • 你可以看到下面的插件部分
            <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <dependencies>
    <dependency>
    <groupId>com.sun</groupId>
    <artifactId>tools</artifactId>
    <scope>system</scope>
    <systemPath>${JDK_HOME}/lib/tools.jar</systemPath>
    </dependency>
    <dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>myArtifact</artifactId>
    <version>1.0</version>
    </dependency>
    </dependencies>
    <configuration>
    <executable>java</executable>
    <arguments>
    <argument>-classpath</argument>
    <classpath/>
    <argument>com.mycompany.MyMainClass</argument>
    </arguments>
    </configuration>
    <executions>
    <execution>
    <goals>
    <goal>exec</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
  • 最佳答案

    最终我决定使用 maven-antrun-plugin 所以这是一个可能的替代解决方案。

    <configuration>
    <target>
    <property name="runtime_classpath" refid="maven.runtime.classpath"/>

    <java classname="com.mycompany.MyClass"
    fork="true"
    spawn="false"
    failonerror="true"
    maxmemory="512m" >

    <classpath>
    <pathelement path="${runtime_classpath}" />
    <pathelement path="${JDK_HOME}/lib/tools.jar" />
    </classpath>
    <arg value="${ant.param1}" />
    <arg value="${ant.param2}" />
    <arg value="${ant.param3}" />
    <arg value="${ant.param4}" />
    <arg value="${ant.param5}" />
    </java>
    </target>
    </configuration>

    关于maven - 将命令行参数添加到 maven exec 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11735949/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com