【问题标题】:Maven exec plugin - user args from console after hardcoded argsMaven exec插件 - 硬编码参数后来自控制台的用户参数
【发布时间】:2013-03-13 13:02:12
【问题描述】:

我正在实现一个简单的 RMI 服务器和客户端。我想加快每次添加服务器代码库的繁琐任务(大量终端膨胀的文本),所以我决定使用 maven exec 插件。这是我的pom.xml 的一部分现在的样子:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-classpath</argument>
                    <argument>/media/files/EclipseWorkspace/JavaSE/rozprochy/lab2/RmiServer/target/classes</argument>
                    <argument>-Djava.rmi.server.codebase=file:/media/files/EclipseWorkspace/JavaSE/rozprochy/lab2/RmiServer/target/classes/</argument>
                    <argument>engine.ComputeEngine</argument>
                </arguments>
            </configuration>
        </plugin>
    </plugins>
</build>

当我在控制台中运行mvn exec:exec 时,一切都很好。当我想让用户指定 rmiregistry 端口作为程序的参数时,就会出现问题。基本上,除了 POM 文件中指定的参数之外,我还想从控制台添加额外的参数。在从控制台指定新参数时,我发现的所有解决方案都覆盖了硬编码的参数,这是不可取的。有没有可能以某种方式做到这一点?

【问题讨论】:

    标签: java maven args exec-maven-plugin


    【解决方案1】:

    这是一种扭曲的解决方法,但我想不出任何其他方法来实现你想要的

    使用附加参数的默认值在 pom 中定义一个属性

    <properties>
        <extra.argument.from.console>extra.argument.from.console.default.value</extra.argument.from.console>
    </properties>
    

    在您的执行中将该属性添加为参数

    <argument>${extra.argument.from.console}</argument>
    

    在调用 maven 时,如果您不想使用默认值,请为该属性赋值

    mvn exec:exec -Dextra.ar​​gument.from.console=value.you.want

    【讨论】:

    • 感谢您的回复,我在这里找到了类似的答案:stackoverflow.com/a/3422989/1066357 这有点解决方法,但经过这么多搜索,我无法指望找到更好的答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 2018-01-09
    • 1970-01-01
    相关资源
    最近更新 更多