exec-maven-plugin说无法运行指定的程序,即使它在PATH上

bgu*_*uiz 11 java path maven-plugin maven node.js

编辑20140716:

找到解决方案

TL; DR = EXEC-Maven的插件也不会承认.cmd的文件,但只有.bat文件,可执行脚本.重命名grunt.cmd --> grunt.bat,bower.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.
Run Code Online (Sandbox Code Playgroud)

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

cd C:\workspace\foobar\src\main\spa
grunt build
Run Code Online (Sandbox Code Playgroud)

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

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


编辑:

这个文档表明PATH应该找到可执行文件,所以它让我更进一步.

bgu*_*uiz 9

我挖了源代码exec-maven-plugin并找到了这个代码片段.

从以下来源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 );
    }
Run Code Online (Sandbox Code Playgroud)

我将此与另一个从maven运行grunt任务的插件进行了比较,并发现了这一点

        if (isWindows()) {
            command = "cmd /c " + command;
        }
Run Code Online (Sandbox Code Playgroud)

......这对我有用.所以基本上后者是有效的,因为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诸如bower和创建的其他可执行文件yo)

  • 我已经阅读了帖子,这就是我第一次来到这里的方式:)这个bug已经从版本1.4解决了.您现在可以指向1.4-SNAPSHOT修复它:https://jira.codehaus.org/browse/MEXEC-118 (2认同)
  • 听起来很有希望,但即使重命名后我也会遇到同样的错误 (2认同)

Pie*_*gen 7

除了bguiz的答案,这将是最好的解决方案,我已经使用Maven配置文件创建了一个解决方法,绕过了这个问题.

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

请在这里提交错误报告:http://jira.codehaus.org/browse/MEXEC-118

编辑:错误已解决,您可以指向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>
Run Code Online (Sandbox Code Playgroud)