为什么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>
最佳答案
看起来这个问题从 2007 年就已经知道了 -> http://mail-archives.apache.org/mod_mbox/maven-users/200708.mbox/%3C5a2cf1f60708090246l216f156esf46cc1e968b37ccd@mail.gmail.com%3E
在您的情况下,您可以尝试使用 <commanlineArgs>
代替配置参数。
如果你有很多论点,这不是很好,但如果你只有一两个,这可能是一个选择。
<configuration>
<executable>${env.JAVA_HOME}/bin/java</executable>
<commandlineArgs>${my.val}</commandlineArgs>
</configuration>
我还在 MEXEC Jira 中创建了一个错误报告:http://jira.codehaus.org/browse/MEXEC-104
更新
通过
<commandlineArgs>
提供类路径, 做这个:<commandlineArgs>-classpath %classpath my.main.class.MyMainClass ${my.val}</commandlineArgs>
实际上,解析器甚至允许折叠长行以使其更具可读性,例如
<commandlineArgs>
-classpath %classpath
my.main.class.MyMainClass
${my.val}
</commandlineArgs>
关于maven - Maven 中的 "Null"与 "empty"参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7773134/