exec-maven-plugin exec:java failing:无法将配置值分配给java.lang.String类型的数组

时间:2012-04-17 10:30:32

标签: java maven exec-maven-plugin

执行mvn exec:java时,无法正确解析配置参数,抛出以下错误:

  

[错误]无法执行目标   org.codehaus.mojo:exec-maven-plugin:1.2.1:java(default-cli)on   project autotest-programs:无法解析mojo的配置   org.codehaus.mojo:exec-maven-plugin:1.2.1:java:无法分配   配置值为java.lang.String类型的数组:[ - classpath,   Classpath {}, - glue,com.company.test.cucumber, - format,pretty,   --format,html:C:\ workspace \ autotest \ target] - > [帮助1]

这是使用的插件配置(使用Apache Maven 3.0.3):

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <includeProjectDependencies>false</includeProjectDependencies>
        <includePluginDependencies>true</includePluginDependencies>
        <executableDependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
        </executableDependency>
        <mainClass>cucumber.cli.Main</mainClass>
        <commandlineArgs>-Dfile.encoding=UTF-8</commandlineArgs>
        <arguments>
            <argument>-classpath</argument>
            <classpath/>
            <argument>--glue</argument>
            <argument>com.company.test.cucumber</argument>
            <argument>--format</argument>
            <argument>pretty</argument>
            <argument>--format</argument>
            <argument>html:${project.basedir}\target</argument>
        </arguments>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.0.2</version>
        </dependency>
    </dependencies>
</plugin>

3 个答案:

答案 0 :(得分:11)

我建议您从配置中删除空条目,然后重试。

 <argument>-classpath</argument>
 <classpath/>

因为在java目标中,不允许基于documentation

的类路径

BTW:永远不要在你的maven pom中使用“\”。改为使用正斜杠。

答案 1 :(得分:2)

根据exec:java Docs here,您必须:

删除<arguments>部分

使用<additionalClasspathElements>声明来定义类路径。

答案 2 :(得分:0)

如果要使用<classpath/>,则必须使用exec:exec而不是exec:java。您还必须添加可执行文件,在您的情况下为java

<executable>java</executable>

如果我正确理解它,exec:java会自动添加您无法覆盖的类路径。参数添加在主类之后。 exec:exec更通用,它执行带有任何参数的任何可执行文件,其中一个可以是<classpath/>