帮别人调试使用程序启动tomcat,开始写如下:
Runtime r = Runtime.getRuntime();
Process p = r.exec("D:/桌面的东西/tomcat/apache-tomcat-6.0.35/bin/startup.bat");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(), "gbk"));
String str = "";
while((str = br.readLine()) != null)
{
System.out.println(str);
}
br.close();
r.gc();
有事没事拉出来走两步,出现如下问题:
The CATALINA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
有点郁闷了……咋一看,CATALINE_HOME环境变量有问题。配置修改成路径后,继续走两步,未果。。。。。
他大爷的,运行的内部机制是什么呢???按住Ctrl + 鼠标点击这个exec()方法。你们多态的exec()方法6个。挨个看了看。
看到这个方面,注解如下:
* @param command a specified system command.
*
* @param envp array of strings, each element of which
* has environment variable settings in the format
* <i>name</i>=<i>value</i>, or
* <tt>null</tt> if the subprocess should inherit
* the environment of the current process.
*
* @param dir the working directory of the subprocess, or
* <tt>null</tt> if the subprocess should inherit
* the working directory of the current process.
dir 子进程的工作目录;如果子进程应该继承当前进程的工作目录,则该参数为 null 。
public Process exec(String command, String[] envp, File dir) throws IOException{}
于是修改exec()中的参数如下:
Process p = Runtime.getRuntime().exec("cmd /c start D:\\桌面的东西\\tomcat\\apache-tomcat-6.0.35\\bin\\catalina.bat start", null, new File("D:\\桌面的东西\\tomcat\\apache-tomcat-6.0.35"));
继续拉出来走两步,,,,,,,,,
OK。