程序中启动tomcat以及The CATALINA_HOME environment vari...

帮别人调试使用程序启动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。

转载于:https://my.oschina.net/Rayn/blog/97937

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值