【问题标题】:exec-maven-plugin exec:java failing: Cannot assign configuration values to array of type java.lang.Stringexec-maven-plugin exec:java失败:无法将配置值分配给java.lang.String类型的数组
【发布时间】:2012-04-28 16:34:38
【问题描述】:

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

[ERROR] 未能执行目标 org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on 项目自动测试程序:无法解析 mojo 的配置 org.codehaus.mojo:exec-maven-plugin:1.2.1:java: 无法分配 java.lang.String 类型数组的配置值:[-classpath, 类路径 {},--glue,com.company.test.cucumber,--format,漂亮, --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>

【问题讨论】:

    标签: java maven exec-maven-plugin


    【解决方案1】:

    我建议从您的配置中删除空条目并重试。

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

    因为在 java 目标中,不允许基于 documentation 的类路径。

    顺便说一句:切勿在 maven pom 中使用“\”。请改用正斜杠。

    【讨论】:

    • 我删除了空条目并将“\”更改为“/”。它从上一个错误继续,但现在抱怨它找不到 mainClass。 [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project autotest-programmes: An exception occured while executing the Java class. cucumber.cli.Main -&gt; [Help 1]
    • 您指的是哪些空条目? ?
    【解决方案2】:

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

    删除&lt;arguments&gt; 部分

    并使用&lt;additionalClasspathElements&gt; 声明来定义类路径。

    【讨论】:

      【解决方案3】:

      如果你想使用&lt;classpath/&gt;,你必须使用exec:exec而不是exec:java。您还必须添加可执行文件,在您的情况下为 java

      <executable>java</executable>
      

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

      【讨论】:

        猜你喜欢
        • 2023-03-07
        • 2016-12-24
        • 1970-01-01
        • 2011-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-21
        相关资源
        最近更新 更多