This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Servlets and the fly likes servlets w/ packages... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets w/ packages..." Watch "servlets w/ packages..." New topic

servlets w/ packages...

Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
This Java CLASSPATH business can be absolutely maddening sometimes.

I simply want to write and display a servlet (with a package) using Resin. I get an error when using packages but it works fine w/o using them.

I *really* need to define packages, this could be a big site w/ many servlets.

My servlet "" in my vir. directory's WEB-INF/classes directory:

My web.xml file, in the WEB-INF directory:

The Resin log is showing me this:

[03:46:05.312] com.caucho.config.LineConfigException: WEB-INF/web.xml:2: `com.scientifik.web.Router' is not a known servlet. Servlets belong in the classpath, often in WEB-INF/classes.

However, my classpath is set to:


Which is exactly correct, echoing the CLASSPATH shows but Resin obviously does not see it.

It is not an issue w/ using Resin w/ IIS as I can get servlets WITHOUT packages to compile w/o a single problem. If I were to remove the "package ..." line from the code and change the "servlet-class" tag in the web.xml file to <servlet-class>Router</servlet-class>, it compiles automatically and runs!

Any ideas?

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12891
If Resin is like Tomcat, it totally ignores the environment CLASSPATH and uses its own rules to find classes.
If your servlet class is com.scientifik.web.Router then the compiled class MUST BE PLACED ACCORDINGLY!!!
This is all laid out in the servlet API documentation which you really really really need to get, read, and understand.
Download the API from here.

If you are getting a servlet to run without a package it may be due to that accursed "invoker" servlet - (read this FAQ here at the ranch).
It is sorta covered in the JavaRanch Style Guide.
subject: servlets w/ packages...