标签:style blog http color io os java ar 文件
生成catalina.out方法
导语:本文为Windows下生tomcat将控制台信息输出到catalina.out文件 且 保证能实时查看日志文件的方法。
一、创建catalina.out
1、修改tomcat bin目录下的startup.bat文件
修改位置:在startup.bat文件倒数第二行
修改call "%EXECUTABLE%" start%CMD_LINE_ARGS%
为:call "%EXECUTABLE%" run %CMD_LINE_ARGS%
2、修改catalina.bat文件
修改位置:catalina.bat文件最后几行
修改为(修改处已用红色标记):
rem Execute Java with the applicable properties
if not "%JPDA%" == "" goto doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION% >> "%CATALINA_BASE%"\logs\catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out
goto end
:doSecurity
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION% >> "%CATALINA_BASE%"\logs\catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out
goto end
:doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION% >> "%CATALINA_BASE%"\logs\catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out
goto end
:doSecurityJpda
%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %JPDA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
>>"%CATALINA_BASE%"\logs\catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out
goto end
:end
3、启动startup.bat文件 查看tomcat logs目录下是否存在catalina.out文件
二、如何实时查看catalina.out文件?
1、安装rktools.exe文件 记录安装路径
2、将rktools.exe安装路径添加PATH环境变量中
在cmd下tail /?,出现以下信息则说明安装成功了:
3、在tomcat bin 目录下新增tomcat_s1log.bat文件(文件名可以自行定义),内容如下:
@echo off
if not exist "%CATALINA_BASE%"\logs\catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out echo "" > "%CATALINA_BASE%"\logs\catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out
tail -f "%CATALINA_BASE%"\logs\catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out
4、修改catalina.bat文件
185行:echo Using JRE_HOME: "%JRE_HOME%"
goto java_dir_displayed
:use_jdk
echo Using JAVA_HOME: "%JAVA_HOME%"
:java_dir_displayed
echo Using CLASSPATH: "%CLASSPATH%"
修改为:
echo Using JRE_HOME: "%JRE_HOME%"
tomcat_s1log.bat
goto java_dir_displayed
:use_jdk
echo Using JAVA_HOME: "%JAVA_HOME%"
:java_dir_displayed
echo Using CLASSPATH: "%CLASSPATH%"
5、启动startup.bat 会看到两个控制台 一个启动信息界面 一个实时日志监控界面
(注:如果想把tomcat_s1log.bat放在桌面启动 则需要修改tomcat_s1log.bat
里面的"%CATALINA_BASE%"修改为对应的tomcat目录。)
例:
d:
cd D:\\Program Files\\apache-tomcat-7.0.5\\logs
if not exist catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out echo "" > catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out
tail -f catalina_%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%.out
标签:style blog http color io os java ar 文件
原文地址:http://www.cnblogs.com/programmerblog/p/SystemEnviroment.html