The moose likes Tomcat and the fly likes Struggling to run code ( java . lang . NoClassDefFoundError: ) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Reply Bookmark "Struggling to run code ( java . lang . NoClassDefFoundError: )" Watch "Struggling to run code ( java . lang . NoClassDefFoundError: )" New topic
Author

Struggling to run code ( java . lang . NoClassDefFoundError: )

GeofferyR Durham
Greenhorn

Joined: Oct 17, 2003
Posts: 15
I'm working in linux. I'm able to compile code but not run it. The generated error type is java.lang.NoClassDefFoundError. I know that the error is generated because java can't find the byte code after the code is compiled.
All the byte code is in "/var/tomcat/bin" and I try to run it from this directory. The defined directories are below. Is there anything else I need to add to the directories?
CLASSPATH =
/var/tomcat/webapps/axis/WEB-INF/lib/axis.jar:
/var/tomcat/webapps/axis/WEB-INF/lib/wsdl4j.jar:
/var/tomcat/webapps/axis/WEB-INF/lib/clutil.jar:
/var/tomcat/webapps/axis/WEB-INF/lib/xerces.jar:
/var/tomcat/webapps/axis/WEB-INF/lib/log4j-core.jar:
/usr/java /j2sdk1.4.2_01 /bin
JAVA_HOME = /usr/java/j2sdk1.4.2_01
PATH = /usr/local/bin:
/usr/bin:
/bin:
/usr/X11R6/bin:
/home/simon/bin:
/usr/java/j2sdk1.4.2_01/bin/
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11863
Exactly what are your trying to run here? A SOAP client?
There is a findingclasses.html page in the SDK docs/tooldocs directory you may find useful.
Bill
GeofferyR Durham
Greenhorn

Joined: Oct 17, 2003
Posts: 15
Sorry its taken so long to get back to you bill. It is a soap client. I found the problem though. I needed to add server.jar found in the tomcat folder to the classpath.
I am having another problem though. I am trying to create an additional context to the tomcat web server. The context seems to have been initialized in the startup of tomcat. However when I type this url; http://localhost:8080/bg/ByteBourmetServer it should invoke a servlet page that would appear in the browser. It doesn't do this, but it generates the following error in the browser:
Not Found (404)
Original request: /bg/ByteGourmetServer
Not found request: /bg/ByteGourmetServer
In the terminal it generates this error:
2003-10-27 11:08:58 - Ctx(/bg) : Status code:404 request:R( /bg +/ByteGourmetServer + null) msg:null
I think the problem is in the web.xml deployment descriptor and where to put the compiled class code so that it can be located when initializing the bg context.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11863
I'm sure you are correct, it just isn't recognizing your web applications.
The following points occur to me:
1. be sure to put your servlet class in a package
2. be sure to follow the convention for locating your web.xml and class files under the WEB-INF subdirectory - see the examples that come with Tomcat. It really pays to have the complete servlet API documentation - you can download a pdf file from java.sun.com - but you have to hunt because they keep fooling around with the organization.
Start at java.sun.com/products/servlet
3. you will have to restart tomcat to get it to see changes in web.xml, (or use the management application)
Bill
GeofferyR Durham
Greenhorn

Joined: Oct 17, 2003
Posts: 15
Hi Bill,
Thanks again for replying. Those guidelines were definitely a help. I reckon its the right area to be concerned with. I tried to create a jar file to make things simpler.
I put all my java files into a package called myServlets. In the CLASSPATH along with all the other concerned directories, I typed

export CLASSPATH = /var/tomcat/webapps/bg/WB_INF/lib/myServlets.jar
This is my web.xml file in WB_INF file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!--Define servlets that are included in the ByteGourmet application -->
<servlet>
<servlet-name>ByteGourmetServer</servlet-name>
<servlet-class>myServlets.ByteGourmetServer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ByteGourmetServer</servlet-name>
<url-pattern>
/ByteGourmetServer
</url-pattern>
</servlet-mapping>
</web-app>
The jar file structure in myServlets.jar looks like this:
myServlets/*.class
Could you give directions on where to find the standard servlet directory.
Thanks
Geof.
[ October 28, 2003: Message edited by: GeofferyR Durham ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11863
If I understand the question, the convention is that all webapplications are under the tomcat/webapps directory unless otherwise specified in the server.xml file. Note that Tomcat does not pay any attention to your environment CLASSPATH setting.
Bill
GeofferyR Durham
Greenhorn

Joined: Oct 17, 2003
Posts: 15
Hi Bill,
Found most of the problems. Miss types in the CLASSPATH and a lack of understanding in other areas. Thanks for helping. Thanks for the additional info. It helped alot.
Cheers
Geof
 
 
subject: Struggling to run code ( java . lang . NoClassDefFoundError: )
 
Threads others viewed
can't generate java from wsdl file please help!
useBean error & classpath setting
Exception in thread main
Problems with security policies for Axis2 in Tomcat
Axis: WSDL2Java classpath problem
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture