We know using proper logging library instead of System.out is important. But when there are a legacy application that still using the System.out and System.err, it will be good to be able to pipe it into file for troubleshooting.
The solution is set the swallowOutput="true" in Tomcat context of your webapp. Then this will pipe the stdout and stderr into the logger configured in the same context.
// shall I write some keywords here to boost search engine ranking?
Monday, September 07, 2009
Redirect Tomcat console output to log file
Wednesday, September 03, 2008
Tomcat: Change console title on Windows
There are 2 ways of running Tomcat on Windows: run as service, run in console.
Although many will suggest to run as service for better performance, but run Tomcat in console have its advantages too. Especially when the web do not do proper file logging, but simply System.out.println.
When running Tomcat with conosle, the default title of the console is "Tomcat" or "Tomcat 5.0.x". It will be confusing if you running multiple Tomcat in same server.
In order to change the console title, below are the steps:
1) Open TOMCAT_HOME/bin/catalina.bat
2) Goto ":doStart" section
3) change the title at line of "set _EXECJAVA" which is 2 or 3 line after ":doStart":
By this small change, the title of the Tomcat console will changed to "Tomcat 5.0.28 (port 8080, AJP port 8009)" which is much more informative.
:doStart
shift
if not "%OS%" == "Windows_NT" goto noTitle
set _EXECJAVA=start "Tomcat 5.0.28 (port 8080, AJP port 8009)" %_RUNJAVA%
Tuesday, January 22, 2008
Run Tomcat on Linux with non-root user on port 80
In Linux, non-root user is not allowed to bind to privileged port (1 - 1024). And for security reason or many others reason, we do not run Tomcat with root user privilege.
This cause our tomcat not able to bind to port 80. This article suggest a few alternative to this problem. Among the alternatives, I prefer the port redirect via iptables.
However, the steps mentioned in the article is not a permanent port redirection. So after some google, I found the steps as below:
1. login as root user
2. type command below to do a port redirection from 80 to 8080:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
3. save the redirection:
iptables-save > /etc/sysconfig/iptables
Done. You can access the Tomcat from others server via port 80. To access from localhost, you still got to access via port 8080.
Wednesday, November 14, 2007
Enable JMX on Tomcat 5 and above
Since Tomcat 5.0, Tomcat manager webapp was introduced. JMX is not enabled by default on Tomcat 5.0 and above.
However, it is easy to enable it. The only pre-requisite is to run the Tomcat on JDK 1.5 or above.
In order to enable JMX on Tomcat 5.0, simply add this line to your catalina.bat:
set JAVA_OPTS=-Dcom.sun.management.jmxremote.port=7009 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=falseThen you may use JConsole that come with JDK 1.5 and above or your favourite JMX client to monitor the Tomcat though port 7009.
Anyway, this will make the JMX open for unauthorised access. Will illustrate the steps to secure the JMX access to Tomcat in coming post.
Sunday, September 02, 2007
Load Balance Tomcat 5.0
Here is the guide to load balance Tomcat 4.1 with Apache Web Server.
I had attempt to follow the steps to load balance Tomcat 5.0 with Apache Web Server and it work well.
Here is the steps to load balance Tomcat 5.0.
Monday, July 31, 2006
Session Persistent in Tomcat
Based on my past experience, I know that Tomcat is able to persist session. Which means user session can be restore after proper shutdown or restart of Tomcat.
However, recently all of my webapps on a Tomcat fail to restore the session. This is strange to me. I do some google to find out where to tweak my Tomcat to enable this. Then I found that it is enable by default, and many people is asking how to disable it.
I try to look into my work directory. When I shutdown, the file "SESSION.ser" which store session is created. When I start Tomcat, it was read then removed. But I still fail to retrieve the items in session.
Then something flash into my mind. The file is "SESSION.ser", ".ser" means serialized object file. The object I put into the session is not serialized, could this be the reason?
After some experiment, what I guess is true. If want to restore the object from session, the object must be serialized.
After doing years of Servlet/JSP, I only realised this by today. What a shame. -_-'''
Posted by Thiam Teck (1983 - ?) at 10:09 PM 2 comments
Tuesday, September 13, 2005
Administrator Login in Tomcat 5
When installing Tomcat 5 on windows with installer, it will prompt user to create a default login for administrator. But it is not the case when installation in Linux just un-tar the file. It is by default no administrator login.
So you need to manually edit the $tomcat_home/conf/tomcat-users.xml as teach is this page:
http://www.linux-sxs.org/internet_serving/c516.html