不能运行程序 "cmd":error=2,没有这样的文件或目录。

问题描述 投票:-2回答:1

这是我的java代码。

import java.io.IOException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

@RestController
class HelloController {
    @GetMapping("/")
    public String testJob() {
        String path="cmd /c start C:\\myfile.bat";

         try
          {
               Runtime.getRuntime().exec(path);
          } catch (IOException e) {
                return e.getMessage();
          }

        return "Done";
    }
} 

当我运行它时,它工作得很好,但在heroku部署后,我得到了这个错误。

Cannot run program "cmd": error=2, No such file or directory

有什么建议吗?

java spring-boot heroku cmd runtime.exec
1个回答
0
投票

这是我的新代码

package com.example.demo;

import local_project.addcase_0_1.addCase;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);

    }
}
@RestController
class HelloController {
    @GetMapping("/")
    public String TestJob() {
        addCase a = new addCase();
        a.runJob(new String[] {});   
        return "Added";
    }
}

我试图在java代码中运行一个talend作业!我按照这些说明做了 https:/help.talend.comreaderLod~TDRaNw2L2VZKV9XgZwty4l9kEdDoVHlHIAOW1e~Q][1] 。 当我运行它时,它工作得很完美,但我不能在heroku上部署它。

remote:        [INFO] 3 errors
remote:        [INFO] -------------------------------------------------------------
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] BUILD FAILURE
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] Total time:  11.171 s
remote:        [INFO] Finished at: 2020-04-28T13:19:02Z
remote:        [INFO] ------------------------------------------------------------------------
remote:        [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project demo: Compilation failure: Compilation failure:
remote:        [ERROR] /tmp/build_555cf666918f4cc22848d177306270f3/src/main/java/com/example/demo/DemoApplication.java:[2,33] package local_project.addcase_0_1 does not exist
remote:        [ERROR] /tmp/build_555cf666918f4cc22848d177306270f3/src/main/java/com/example/demo/DemoApplication.java:[22,17] cannot find symbol
remote:        [ERROR]   symbol:   class addCase
remote:        [ERROR]   location: class com.example.demo.HelloController
remote:        [ERROR] /tmp/build_555cf666918f4cc22848d177306270f3/src/main/java/com/example/demo/DemoApplication.java:[22,33] cannot find symbol
remote:        [ERROR]   symbol:   class addCase
remote:        [ERROR]   location: class com.example.demo.HelloController
remote:        [ERROR] -> [Help 1]
remote:        [ERROR]
remote:        [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
remote:        [ERROR] Re-run Maven using the -X switch to enable full debug logging.
remote:        [ERROR]
remote:        [ERROR] For more information about the errors and possible solutions, please read the following articles:
remote:        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
remote:
remote:  !     ERROR: Failed to build app with Maven
remote:        We're sorry this build is failing! If you can't find the issue in application code,
remote:        please submit a ticket so we can help: https://help.heroku.com/
remote:
remote:  !     Push rejected, failed to compile Java app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to excel-to-case.
remote:
To https://git.heroku.com/excel-to-case.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/excel-to-case.git'
© www.soinside.com 2019 - 2024. All rights reserved.