开发者

"Null" versus "empty" arguments in Maven

开发者 https://www.devze.com 2023-04-13 07:44 出处:网络
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

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>


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

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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消