“空”与“空”相对Maven 中的参数

发布于 2024-12-10 03:33:46 字数 2113 浏览 1 评论 0 原文

为什么 Maven 坚持将空字符串和空格字符串视为“空值”?采取以下 pom - 我收到有关参数配置错误的常见虚假消息。我怎样才能安排传递一个 Maven 真正能够识别的空值,而不是用荒谬的错误消息来折磨我?

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Misconfigured argument, value is null. Set the argument to an empty value if this is the required behaviour.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <packaging>pom</packaging>
    <version>0</version>
    <name>test</name>
    <url>http://maven.apache.org</url>
    <properties>
        <my.val>             </my.val>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>Exec test</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${env.JAVA_HOME}/bin/java</executable>
                            <arguments>
                                <argument>${my.val}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Why does Maven insist on treating empty strings and strings of spaces "null values"? Take the following pom - I get the usual bogus message about a misconfigured argument. How can I arrange to pass an empty value that Maven will actually recognize as such instead of tormenting me with absurd error messages?

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Misconfigured argument, value is null. Set the argument to an empty value if this is the required behaviour.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <packaging>pom</packaging>
    <version>0</version>
    <name>test</name>
    <url>http://maven.apache.org</url>
    <properties>
        <my.val>             </my.val>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>Exec test</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${env.JAVA_HOME}/bin/java</executable>
                            <arguments>
                                <argument>${my.val}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌路终见情 2024-12-17 03:33:47

看起来这个问题自 2007 年以来就已为人所知 -> http://mail-archives.apache.org/mod_mbox/maven-users/200708.mbox/%[电子邮件受保护]%3E

在您的情况下,您可以尝试改用 配置参数。

如果你有很多争论,那就不太好,但如果你只有一两个,这可能是一个选择。

<configuration>
  <executable>${env.JAVA_HOME}/bin/java</executable>
  <commandlineArgs>${my.val}</commandlineArgs>
</configuration>

我还在 MEXEC Jira 中创建了错误报告: http://jira.codehaus.org/browse /MEXEC-104

UPDATE

要通过 提供类路径,请执行以下操作:

<commandlineArgs>-classpath %classpath my.main.class.MyMainClass ${my.val}</commandlineArgs>

实际上,解析器甚至允许折叠长行使其更具可读性,例如

<commandlineArgs>
  -classpath %classpath
  my.main.class.MyMainClass
  ${my.val}
</commandlineArgs>

Looks like the problem has been known since 2007 -> http://mail-archives.apache.org/mod_mbox/maven-users/200708.mbox/%[email protected]%3E

In your case you may try to use <commanlineArgs> configuration parameter instead.

It's not pretty if you have many arguments, but if you only have one or two it may be an option.

<configuration>
  <executable>${env.JAVA_HOME}/bin/java</executable>
  <commandlineArgs>${my.val}</commandlineArgs>
</configuration>

I've also created a bug report in MEXEC Jira: http://jira.codehaus.org/browse/MEXEC-104

UPDATE

To supply a classpath through <commandlineArgs>, do this:

<commandlineArgs>-classpath %classpath my.main.class.MyMainClass ${my.val}</commandlineArgs>

Actually, the parser even allows folding of the long line to make it more readable, e.g.

<commandlineArgs>
  -classpath %classpath
  my.main.class.MyMainClass
  ${my.val}
</commandlineArgs>
云淡风轻 2024-12-17 03:33:47

您可以将 my_val 设置为一些虚拟系统属性值,例如 -Ddummy=dummy
我知道这并不优雅,但至少是一种解决方法。

You can set my_val to some dummy system property value like -Ddummy=dummy.
I know it is not elegant but at least a workaround.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文