同上。Runtime.getRuntime().exec("路径\\tamcat.exe");

解决方案 »

  1.   

    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec("C:\\Tomcat\\bin\\shutdown.bat");
    Process process = runtime.exec("C:\\Tomcat\\bin\\startup.bat");
      

  2.   

    to: Acylas(Acylas)你的代码我运行以后什么也没有出现啊,怎么运行?
      

  3.   

    C:\\Tomcat\\bin\\shutdown.bat
    你的目录也是这个吗?
      

  4.   

    to:Acylas(Acylas) 目录我已经更改过的了,执行以后什么提示也没有,也没有出现什么窗口。是不是还要执行一下process对象?
      

  5.   

    不用。
    用下面这种办法,看看提示打印什么问题
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec("C:\\Tomcat\\bin\\shutdown.bat");
    runtime.gc();
    BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String line = null, result = "";
    while ((line = input.readLine()) != null)
       result += line + "\r\n";
    input.close();
    System.out.println(result);
    process = runtime.exec("C:\\Tomcat\\bin\\shutdown.bat");
      

  6.   

    The CATALINA_HOME environment variable is not defined correctly
    This environment variable is needed to run this program显示这个
      

  7.   

    哦,这个是你那bat文件本身有问题,不是java程序有问题。
    你用的tomcat5.0?没有设置CATALINA_HOME吧?你用记事本打开这两个bat文件
    应该看到下面这几行吧,因为exist "%CATALINA_HOME%\bin\catalina.bat"这条件不成立
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end看看在上面语句的前面有没有下面这几行,设置"%CATALINA_HOME%的
    rem Guess CATALINA_HOME if not defined
    if not "%CATALINA_HOME%" == "" goto gotHome
    set CATALINA_HOME=.
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    set CATALINA_HOME=..
    :gotHome
    :okHome
      

  8.   

    rem Guess CATALINA_HOME if not defined
    set CURRENT_DIR=%cd%
    if not "%CATALINA_HOME%" == "" goto gotHome
    set CATALINA_HOME=%CURRENT_DIR%
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    cd ..
    set CATALINA_HOME=%cd%
    cd CURRENT_DIR
    :gotHome
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end
    :okHomeset EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat
    我加了CATALINA_HOME系统变量,不过还是输出一样的东西,应该怎么修改?
      

  9.   

    怎么有%cd%和%CURRENT_DIR%这两个的?你试试改成下面这样,
    rem Guess CATALINA_HOME if not defined
    set CURRENT_DIR=.                        表示这个批处理相同目录
    if not "%CATALINA_HOME%" == "" goto gotHome
    set CATALINA_HOME=..                     表示上一层目录
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    cd ..
    set CATALINA_HOME=%cd%
    cd CURRENT_DIR
    :gotHome
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end
    :okHomeset EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat
    如果不行,你将整个批处理的内容贴出来
      

  10.   

    我的shutdonw.bat的是这样的啊
    @echo off
    if "%OS%" == "Windows_NT" setlocal
    rem ---------------------------------------------------------------------------
    rem Stop script for the CATALINA Server
    rem
    rem $Id: shutdown.bat,v 1.3 2002/08/04 18:19:43 patrickl Exp $
    rem ---------------------------------------------------------------------------rem Guess CATALINA_HOME if not defined
    if not "%CATALINA_HOME%" == "" goto gotHome
    set CATALINA_HOME=.
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    set CATALINA_HOME=..
    :gotHome
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end
    :okHomeset EXECUTABLE=%CATALINA_HOME%\bin\catalina.batrem Check that target executable exists
    if exist "%EXECUTABLE%" goto okExec
    echo Cannot find %EXECUTABLE%
    echo This file is needed to run this program
    goto end
    :okExecrem Get remaining unshifted command line arguments and save them in the
    set CMD_LINE_ARGS=
    :setArgs
    if ""%1""=="""" goto doneSetArgs
    set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
    shift
    goto setArgs
    :doneSetArgscall "%EXECUTABLE%" stop %CMD_LINE_ARGS%:end返回还是The CATALINA_HOME environment variable is not defined correctly
    This environment variable is needed to run this program
      

  11.   

    startup.bat:@echo off
    if "%OS%" == "Windows_NT" setlocal
    rem ---------------------------------------------------------------------------
    rem Start script for the CATALINA Server
    rem
    rem $Id: startup.bat,v 1.5 2004/03/28 06:40:44 mturk Exp $
    rem ---------------------------------------------------------------------------rem Guess CATALINA_HOME if not defined
    set CURRENT_DIR=%cd%
    if not "%CATALINA_HOME%" == "" goto gotHome
    set CATALINA_HOME=%CURRENT_DIR%
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    cd ..
    set CATALINA_HOME=%cd%
    cd CURRENT_DIR
    :gotHome
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end
    :okHomeset EXECUTABLE=%CATALINA_HOME%\bin\catalina.batrem Check that target executable exists
    if exist "%EXECUTABLE%" goto okExec
    echo Cannot find %EXECUTABLE%
    echo This file is needed to run this program
    goto end
    :okExecrem Get remaining unshifted command line arguments and save them in the
    set CMD_LINE_ARGS=
    :setArgs
    if ""%1""=="""" goto doneSetArgs
    set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
    shift
    goto setArgs
    :doneSetArgscall "%EXECUTABLE%" start %CMD_LINE_ARGS%:end
    shutdonw.bat:
    @echo off
    if "%OS%" == "Windows_NT" setlocal
    rem ---------------------------------------------------------------------------
    rem Stop script for the CATALINA Server
    rem
    rem $Id: shutdown.bat,v 1.4 2004/03/28 06:40:44 mturk Exp $
    rem ---------------------------------------------------------------------------rem Guess CATALINA_HOME if not defined
    set CURRENT_DIR=%cd%
    if not "%CATALINA_HOME%" == "" goto gotHome
    set CATALINA_HOME=%CURRENT_DIR%
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    cd ..
    set CATALINA_HOME=%cd%
    cd CURRENT_DIR
    :gotHome
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end
    :okHomeset EXECUTABLE=%CATALINA_HOME%\bin\catalina.batrem Check that target executable exists
    if exist "%EXECUTABLE%" goto okExec
    echo Cannot find %EXECUTABLE%
    echo This file is needed to run this program
    goto end
    :okExecrem Get remaining unshifted command line arguments and save them in the
    set CMD_LINE_ARGS=
    :setArgs
    if ""%1""=="""" goto doneSetArgs
    set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
    shift
    goto setArgs
    :doneSetArgscall "%EXECUTABLE%" stop %CMD_LINE_ARGS%:end
      

  12.   

    你备份一下你的这两个文件,我贴个新的你试试(记得改java_home的目录:
    set JAVA_HOME=C:\j2sdk1.4.2这一行)
    startup对应的
    @echo off
    if "%OS%" == "Windows_NT" setlocal
    rem ---------------------------------------------------------------------------
    rem Start script for the CATALINA Server
    rem
    rem $Id: startup.bat,v 1.4 2002/08/04 18:19:43 patrickl Exp $
    rem ---------------------------------------------------------------------------set JAVA_HOME=C:\j2sdk1.4.2
    rem Guess CATALINA_HOME if not defined
    if not "%CATALINA_HOME%" == "" goto gotHome
    set CATALINA_HOME=.
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    set CATALINA_HOME=..
    :gotHome
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end
    :okHomeset EXECUTABLE=%CATALINA_HOME%\bin\catalina.batrem Check that target executable exists
    if exist "%EXECUTABLE%" goto okExec
    echo Cannot find %EXECUTABLE%
    echo This file is needed to run this program
    goto end
    :okExecrem Get remaining unshifted command line arguments and save them in the
    set CMD_LINE_ARGS=
    :setArgs
    if ""%1""=="""" goto doneSetArgs
    set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
    shift
    goto setArgs
    :doneSetArgscall "%EXECUTABLE%" start %CMD_LINE_ARGS%:end
    shutdown对应的
    @echo off
    if "%OS%" == "Windows_NT" setlocal
    rem ---------------------------------------------------------------------------
    rem Stop script for the CATALINA Server
    rem
    rem $Id: shutdown.bat,v 1.3 2002/08/04 18:19:43 patrickl Exp $
    rem ---------------------------------------------------------------------------set JAVA_HOME=C:\j2sdk1.4.2
    rem Guess CATALINA_HOME if not defined
    if not "%CATALINA_HOME%" == "" goto gotHome
    set CATALINA_HOME=.
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    set CATALINA_HOME=..
    :gotHome
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end
    :okHomeset EXECUTABLE=%CATALINA_HOME%\bin\catalina.batrem Check that target executable exists
    if exist "%EXECUTABLE%" goto okExec
    echo Cannot find %EXECUTABLE%
    echo This file is needed to run this program
    goto end
    :okExecrem Get remaining unshifted command line arguments and save them in the
    set CMD_LINE_ARGS=
    :setArgs
    if ""%1""=="""" goto doneSetArgs
    set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
    shift
    goto setArgs
    :doneSetArgscall "%EXECUTABLE%" stop %CMD_LINE_ARGS%:end