Servlets, classpath and NoClassDefFoundError

F

Froggy

Alrighty, I am (still) new to all this Java stuff, and it is causing
me a lot of grief. I am trying to implement a class that to
authenticate web users. I originally had the class as a part of the
webpage itself (not a class, but code within doPost) and it worked
fine. I could import and use the JDBC stuff and perform queries and
whatnot. As soon as I seperated it into its own class, everything
goes beserk:
java.lang.NoClassDefFoundError: request/tools/Login

Now, when I compile Login.java and my webpage, I include everything in
my class path:
...\lib\jxl.jar;..\lib\

The lib folder contains javx, jbdc and everything else I use, and I
can import and use them perfectly. However, mine doesnt work.
I actually took my Login.java file from something else that already
worked before as a class, until I got my hands on it. I even copied
the contructor and everything.

Basically, could someone:
1) explain to me how the compilation and execution of Java servlets
works.
2) explain to me why I am getting and NoClassDefFoundError
3) fix it for me.
Thanks
-Pieter
 
E

Eki Y. Baskoro

G'Day,

You need to store your Login.class file under
$WEBAPP_DIR/WEB-INF/classes/request/tools directory, where $WEBAPP_DIR
depends on which Web Container and Application Context you are currently
using. For example, if you are using Tomcat and you are deploying your Web
Application under / (root) Context, then WEBAPP_DIR would be
$CATALINA_HOME/webapps, where CATALINA_HOME is the path to your Tomcat
installation.
 
W

William Brogden

Froggy said:
Alrighty, I am (still) new to all this Java stuff, and it is causing
me a lot of grief. I am trying to implement a class that to
authenticate web users. I originally had the class as a part of the
webpage itself (not a class, but code within doPost) and it worked
fine. I could import and use the JDBC stuff and perform queries and
whatnot. As soon as I seperated it into its own class, everything
goes beserk:
java.lang.NoClassDefFoundError: request/tools/Login

Now, when I compile Login.java and my webpage, I include everything in
my class path:
..\lib\jxl.jar;..\lib\

The lib folder contains javx, jbdc and everything else I use, and I
can import and use them perfectly. However, mine doesnt work.
I actually took my Login.java file from something else that already
worked before as a class, until I got my hands on it. I even copied
the contructor and everything.

Basically, could someone:
1) explain to me how the compilation and execution of Java servlets
works.

Go to java.sun.com/products/servlet - download the API, browse
the articles, do a search for servlets tutorials
2) explain to me why I am getting and NoClassDefFoundError

Possibly because servlet containers don't always use environment
classpath.
 
F

Froggy

I tried doing this, and I added the classes dir to my classpath when
compiling both Login.java and my servlet application, and I am still
getting the same error. Could someone explain how Java works in terms
of servlets, classes, imports and compilations so that I can
understand why there is an error and how to fix it?
-Pieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top