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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10189504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:00:01  来源:igfitidea点击:

exec-maven-plugin exec:java failing: Cannot assign configuration values to array of type java.lang.String

javamavenexec-maven-plugin

提问by David Camilleri

When executing mvn exec:javait fails to correctly parse the configuration arguments, throwing the following error:

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

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project autotest-programmes: Unable to parse configuration of mojo org.codehaus.mojo:exec-maven-plugin:1.2.1:java: Cannot assign configuration values to array of type java.lang.String: [-classpath, Classpath {}, --glue, com.company.test.cucumber, --format, pretty, --format, html:C:\workspace\autotest\target] -> [Help 1]

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

This is the plugin configuration used (using Apache Maven 3.0.3):

这是使用的插件配置(使用 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>

采纳答案by khmarbaise

I would suggest to remove the empty entries from your configuration and try it again.

我建议从您的配置中删除空条目,然后再试一次。

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

Cause in java goal the classpath is not allowed based on the documentation.

原因在 java 目标中,基于文档不允许类路径。

BTW: Never use "\" in your maven pom. Use forward slashes instead.

顺便说一句:永远不要在你的 maven pom 中使用“\”。请改用正斜杠。

回答by Alex Chernin

According to exec:java Docs here, you have to :

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

Remove <arguments>part

移除<arguments>零件

And use <additionalClasspathElements>declarations to define a classpath.

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

回答by Oliv

If you want to use <classpath/>, you have to use exec:execand not exec:java. You also have to add the executable, which is javain your case:

如果你想使用<classpath/>,你必须使用exec:exec而不是exec:java。您还必须添加可执行文件,这是java您的情况:

<executable>java</executable>

If I understand it correctly, exec:javaautomatically adds the classpath you cannot override it. The arguments are added after the main class. exec:execis more generic, it executes any executable with any arguments, one of which can be the <classpath/>.

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