maven - Maven 中的 "Null"与 "empty"参数

标签 maven

为什么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/

相关文章:

maven - 如何为maven父项目生成jar

java - 使用 Maven 程序集插件包含特定依赖项

node.js - 通过maven前端插件或命令行选项从 'npm install'输出调试到文件?

java - 防止从 Git 存储库 pull 时需要 "add external jars"

java - 为什么部署后在 RESTEasy (wildfly) 上出现 404 错误?

java - 哪个版本的 Maven Artifact 适用于哪个 JVM

java - 在 docker 镜像中部署 WAR 文件的正确方法

java - 如何从 java docker 容器应用程序解析文件

maven - 不使用 Spring Boot 作为父 pom 会有什么后果?

maven - 杀死自叉 JVM。 PING 超时已过