facegale
JA_GW
2017-10-27 15:06

java web项目里用 java Runtime 执行 java命令报错

5
  • java
  • tomcat
  • runtime

部署在本机(Windows)的tomcat上的web项目

     Runtime runtime = Runtime.getRuntime();
     String[] strings = {"cd\\ \n","F: \n","cd "+path+"\n","javac "+className+".java\n","java "","cd "+path+"\n",

     Process process = runtime.exec("cmd");

     bw = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
    for(int i = 0;i < strings.length;i++){
            bw.write(strings[i]);
            bw.flush();
     }

     bw.close();


javac 命令成功执行了,但java className 命令确报错 找不到或无法加载主类

同样的代码在本地 eclipse上能成功执行

求问 是什么原因

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答