【问题标题】:exec-maven-plugin says cannot run specified program, even though it is on the PATHexec-maven-plugin 说不能运行指定的程序,即使它在 PATH 上
【发布时间】:2014-04-19 01:58:31
【问题描述】:

编辑 20140716

Solution found

tl;dr = exec-maven-plugin .cmd 文件识别为可执行脚本,但仅将 .bat 文件识别为可执行脚本。重命名 grunt.cmd --> grunt.batbower.cmd --> bower.bat 等作为解决方法。


在我的系统上完成npm install -g grunt-cli 之后,grunt 肯定是在PATH

但是,当我运行 maven install 时,这似乎没有注册。

    [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 
    (build-spa-bower) on project foobar: Command execution failed. 
    Cannot run program "grunt" (in directory "C:\workspace\foobar\src\main\spa"): 
    CreateProcess error=2, The system cannot find the file specified -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: 
    Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec 
    (build-spa-bower) on project foobar: Command execution failed.

为了确定,在同一个终端中,我已经执行了这个

cd C:\workspace\foobar\src\main\spa
grunt build

...在我发出上面的 maven 命令的同一终端中,grunt 执行得很好。

exec-maven-plugin 是否使用了PATH 环境变量,或者是否需要告诉它这个可执行文件以其他方式存在?


编辑:

这个documentation 建议应该找到PATH 上的可执行文件,所以这让我更加困惑。

【问题讨论】:

    标签: java node.js maven path maven-plugin


    【解决方案1】:

    我挖了exec-maven-plugin的源码,发现了这个sn-p。

    来自ExecMojo#getExecutablePath的来源:

        CommandLine toRet;
        if ( OS.isFamilyWindows() && exec.toLowerCase( Locale.getDefault() ).endsWith( ".bat" ) )
        {
            toRet = new CommandLine( "cmd" );
            toRet.addArgument( "/c" );
            toRet.addArgument( exec );
        }
        else
        {
            toRet = new CommandLine( exec );
        }
    

    我将它与另一个从 maven 运行 grunt 任务的插件进行了比较,found this

            if (isWindows()) {
                command = "cmd /c " + command;
            }
    

    ... 这对我有用。所以本质上后者是有效的,因为 WINdows 中的所有命令都以cmd /c 开头, 而exec-maven-plugin 没有,因为它只对以.bat 结尾的文件这样做。

    查看C:\Users\USER\AppData\Roaming\npm,我看到了:

    • node_modules(文件夹)
    • grunt(unix 脚本文件)
    • grunt.cmd(Windows 脚本文件)

    当我重命名grunt.cmd --> grunt.bat 时,问题就解决了,exec-maven-plugin 可以运行这个命令。

    (这也适用于使用npm install -g 创建的其他可执行文件,例如boweryo

    【讨论】:

    • 感谢您找到此问题的原因。我已经在这里提交了一个补丁,如果你有同样的问题,请点赞! jira.codehaus.org/browse/MEXEC-137
    • 显然此问题与jira.codehaus.org/browse/MEXEC-118 重复,尚未解决。
    • @PietvanDongen 不客气!顺便说一句,您可能会发现这篇文章很有趣:Making Maven Grunt, Windows Edition - 请参阅“为什么我的插件找不到可执行文件?”部分
    • 我已经阅读了这篇文章,这就是我最初到达这里的方式:) 从 1.4 版开始,该错误已得到解决。您现在可以指向 1.4-SNAPSHOT 进行修复:jira.codehaus.org/browse/MEXEC-118
    • 听起来很有希望,但即使重命名后我也会遇到同样的错误
    【解决方案2】:

    除了 bguiz 的回答(这将是最好的解决方案)之外,我还使用 Maven 配置文件创建了一个解决方法,绕过了该问题。

    这是一个临时解决方案,直到 maven-exec-plugin 的错误得到修复。

    请在此处为错误报告投票:http://jira.codehaus.org/browse/MEXEC-118

    编辑: bug 已解决,您可以指向 1.4-SNAPSHOT 进行修复。

    <project>
    (...)
        <profiles>
            <profile>
                <id>grunt-exec-windows</id>
                <activation>
                    <os>
                        <family>Windows</family>
                    </os>
                </activation>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <version>${exec-maven-plugin.version}</version>
                            <executions>
                                <execution>
                                    <id>grunt-default</id>
                                    <phase>generate-resources</phase>
                                    <configuration>
                                        <executable>cmd</executable>
                                        <arguments>
                                            <argument>/C</argument>
                                            <argument>grunt</argument>
                                        </arguments>
                                    </configuration>
                                    <goals>
                                        <goal>exec</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
    </project>
    

    【讨论】:

    • 我尝试使用此命令,我的 maven 回复 Process exited with an error: 1 (Exit value: 1) 任何想法如何从 maven 获取更多调试信息?
    【解决方案3】:

    我在 1.5.0 的插件中遇到了同样的问题。

    在我的情况下,原因是我的用户名中的空格导致了一个 grunt 路径: C:\Users\我的名字带空格\AppData\Roaming\npm。

    当我将 npm 目录的内容移动到没有空格的路径时,它起作用了。

    【讨论】:

    • 请查看其他答案并点赞以了解答案外壳的外观以及应提供哪些信息。此外,请查看how do I write a good answer
    猜你喜欢
    • 2012-11-08
    • 2012-03-13
    • 2016-11-24
    • 2018-08-06
    • 2011-07-03
    • 2017-08-02
    • 2014-04-19
    • 1970-01-01
    • 2016-01-31
    相关资源
    最近更新 更多