Sunday, August 10, 2008

Some Problems of Tomcat on Ubuntu 8.10

I found that Tomcat 5.5 package of Ubuntu Linux had some serious problems.

Normal users can't control Tomcat server. If you want to start/restart/shutdown Tomcat, you must use "sudo". For developers, restarting Tomcat is very frequent, therefore, typing "sudo" again and again becomes a dirty work.

Problems about MySQL connection. The default bootstrap of Tomcat is /etc/init.d/tomcat5.5 and it starts Tomcat server automatically. But the serious problem is: Tomcat con't connect to MySQL database! I don't know why. However, if I start Tomcat with /usr/share/tomcat5.5/bin/startup.sh, Tomcat can connect to MySQL. Why the two methods to start Tomcat are different?

Class loading problems. I wrote my first servlet that can connect MySQL with JDBC and found some strange problems. I create three files:
  • Database.java: the database class, which encapsulates some database operations;
  • DBTestServlet.java: the servlet class that calls Database class to operate database.
All files (class file, jar file, web.xml, etc) are located in proper directory. But Tomcat said it can't find the JDBC driver class (Database class has a method that calls DriverManager.getConnection() to get a database connection), although I had put mysql-connector-java-5.1.6-bin.jar in WEB-INF/lib. But if I used JDBC API in DBTestServlet class directly, no problem happened. However, the stranger is: if I started Tomcat from root account (I need to enable root accout and use "su" to switch to root, see Enable and Disable "root" on Ubuntu Linux) instead of using "sudo", no problem happened, even if I used Database class. That's very strange.

I don't know why Ubuntu's Tomcat package has so many problems. Perhaps the best solution is to download Tomcat from http://tomcat.apache.org/ and extract it to a directory instead of using "sudo apt-get install tomcat5.5".

1 comment:

Anonymous said...

You're using 8.10 which isn't released yet, so my guess is that you're trying to use the new Tomcat 6 which is included in the new release.

I'd have a look at this blog post to see if it solves your problem:
http://ubuntuserver.wordpress.com/2008/09/01/tomcat-6-lands-in-intrepid/

If you still think it's a problem report the specific problems on the package:
https://bugs.edge.launchpad.net/ubuntu/+source/tomcat6