*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets w/ packages..." Watch "servlets w/ packages..." New topic
Author

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 "Router.java" 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:


.;C:\Inetpub\wwwroot\scientifik.com\WEB-INF\classes


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?

Thanks!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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!!!
WEB-INF/classes/com/scientifik/web/Router.class
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).
Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: servlets w/ packages...
 
Similar Threads
beginner question:error 404 servlet not available in Tomcat
Servlet not running
resin configuration file
Servlet package and Tomcat Question
package issue