“空"对比“空" Maven中的论点 [英] "Null" versus "empty" arguments in Maven

查看:64
本文介绍了“空"对比“空" Maven中的论点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Maven坚持要处理空字符串和空格字符串空值"?请看下面的pom-我得到关于配置错误的参数的通常的虚假消息.我该如何安排传递一个Maven会真正识别出的空值,而不是用荒谬的错误消息折磨我呢?

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>

推荐答案

该问题自2007年以来就已为人所知->

Looks like the problem has been known since 2007 -> http://mail-archives.apache.org/mod_mbox/maven-users/200708.mbox/%3C5a2cf1f60708090246l216f156esf46cc1e968b37ccd@mail.gmail.com%3E

根据您的情况,您可以尝试使用<commanlineArgs>配置参数.

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>

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

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

更新

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

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>

这篇关于“空"对比“空" Maven中的论点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆