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

 一片绿洲053766 发布于 2023-01-18 10:53

编辑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.

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

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

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

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


编辑:

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

2 个回答
  • 我挖了源代码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 );
        }
    

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

            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诸如bower和创建的其他可执行文件yo)

    2023-01-18 10:56 回答
  • 除了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>
    

    2023-01-18 10:56 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有