Sunday, May 03, 2009

Frustrations of a Java developer: Tomcat, Jetty both suck

Ok: now, this should not be rocket surgery: I just want to start from a clean slate, download a servlet container (like Jetty or Tomcat) in its own non-modified directory, create a trivial web app (web.xml, index.html and a jsp file), and run it with default settings.
Easy? You might think so.

But not necessarily so: with both Tomcat and Jetty, chances are you (I) will STILL bump into multiple dead ends (after what, 10 years of development for these containers!), with unhelpful error messages. Yes, I could make an IDE auto-generate much of the stuff, but that should only be automating what I would do manually anyway. And true. I should be cut'n pasting working configs (which I do, just didn't have thing to carbon copy at hand). Even then, I should be able to get things going in a jiffy with all the experience using this dog-forsaken beasts.

So what happens with the default settings? With Jetty, I got this:

[tatu@www sample-struts2]$ java -jar jetty/start.jar cfg/jetty.xml
java.lang.ClassNotFoundException: org.mortbay.xml.XmlConfiguration
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at org.mortbay.start.Main.invokeMain(Main.java:179)
at org.mortbay.start.Main.start(Main.java:523)
at org.mortbay.start.Main.main(Main.java:119)

And this with proper (?) setting for system property "jetty.home" (I think). As a seasoned Jetty veteran, I should be able to figure it out (and I will). It is somehow using some default class path discovery which doesn't find what it's looking for. Disappointing.

But because of this unfortunate hickup, I thought I'll check out Tomcat 6, since one thing it has going for it is clean (I thought) separation between standard Tomcat deployment (with CATALINA_HOME), and actual custom deployment of web apps (with CATALINA_BASE). Also with version 6, its configurability has improved a lot, even though it is still incomplete (why the hell does it not let you log to places outside of "$CATALINA_BASE/logs"?!?), and thus it's not quite as frustrating to deploy.

Ok... let's see... at first I do manage to get it to deploy, but with its default web apps not mine. Ok, had BASE and HOME mixed up. Correct this and... worse:

Exception in thread "main" java.lang.NoClassDefFoundError:
Caused by: java.lang.ClassNotFoundException:
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: .  Program will exit.

Seems obvious? If you think so, you are mistaken (if understandably so): no, this is NOT due to not finding a class due to failure of class introspection.
After LOTS of trial and error, I found out that the real problem is this: all configuration files MUST BE FOUND FROM UNDER $CATALINA_BASE/conf! Never mind that $CATALINA_BASE would have very suitable defaults. Tomcat doesn't care -- it should, mind you -- and does not try checking for common failure conditions.

But the really scary part is that idiotic error message: turns out it is the result of specifically finding file "$CATALINA_BASE/conf/logging.properties" (of all things). So why does it complaing about not finding a class? Who knows? Maybe it just quietly ignores the fact that no properties file is found, and then bumps into not having proper setting for logger class. And its vague enough that I couldn't find anything relevant by googling. Maybe this entry will fix that particular challenge at least.

And the final insult is that the error message only goes to the log file -- from console, things seem to go quite ok.

I am beginning to despise Tomcat 6 as much as its predecessors (wasted too much of my time with Tomcat 4, back in the day). And I'm not entirely happy with Jetty either.

blog comments powered by Disqus

Sponsored By


Related Blogs

(by Author (topics))

Powered By

About me

  • I am known as Cowtowncoder
  • Contact me at@yahoo.com
Check my profile to learn more.