Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

servlet NoClassDefFoundError - help?

0 views
Skip to first unread message

Ron

unread,
Feb 21, 2001, 10:15:31 AM2/21/01
to
My thanks to whomever of you can help me resolve this. This seems to
me like one of those extremely simple errors that make you smack your
forehead and wish you take back the question at all.

OK, I'm having trouble getting a simple servlet example to work right.

I suspect I have some piece of something pointing to wrong place, or
something IN the wrong place. I'm just not up to speed enough to determine
exactly what that might be.

My setup:
Solaris7
java version "1.3.0"
JSDK2.0
JBOSS_HOME=/u/jboss_tomcat/jboss-2.0-FINAL
TOMCAT_HOME=/u/jboss_tomcat/tomcat-3.2-b7
using the jBoss/TomCat bundled distribution from the jBoss web site.

Sorry that this is so long, but I'm hoping I'll be including enough
information so that someone familiar with this can look at it and say "Oh,
THERE'S the problem."

The servlet deploys:
[Auto deploy] Auto deploy of
file:/u/jboss_tomcat/jboss-2.0-FINAL/deploy/ints.war
[J2EE Deployer] Deploy J2EE application:
file:/u/jboss_tomcat/jboss-2.0-FINAL/deploy/ints.war
[J2EE Deployer] Create application ints.war
[J2EE Deployer] Installing web package: ints.war
[J2EE Deployer] Starting module ints.war
[EmbeddedTomcat] ContextManager: Adding context Ctx( /ints )
[EmbeddedTomcat] path="/ints" :org.apache.jasper.servlet.JspServlet: init
[J2EE Deployer] J2EE application:
file:/u/jboss_tomcat/jboss-2.0-FINAL/deploy/ints.war is deployed.

and going to http://localhost:8080/ints produces the index.html I placed
in the .war file. Clicking the link I have on that page to call the servlet
returns
this error on the browser:

Error: 500
Location: /ints/servlet/EJB
Internal Servlet Error:
java.lang.NullPointerException
at java.lang.ClassLoader.resolveClass0(Native Method)
at java.lang.ClassLoader.resolveClass(ClassLoader.java:588)
at
org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:518)
at
org.apache.tomcat.loader.AdaptiveServletLoader.loadClass(AdaptiveServletLoader.java:174)
at
org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:265)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
at org.apache.tomcat.core.Handler.service(Handler.java:254)
at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:799)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:745)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:407)
at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)

and this lengthy error in the jBoss log:

[EmbeddedTomcat] Ctx( /ints ): Exception in init null
java.lang.NullPointerException
at java.lang.ClassLoader.resolveClass0(Native Method)
at java.lang.ClassLoader.resolveClass(ClassLoader.java:588)
at
org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:430)
at
org.apache.tomcat.loader.AdaptiveServletLoader.loadClass(AdaptiveServletLoader.java:174)
at
org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:265)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
at org.apache.tomcat.core.Handler.service(Handler.java:254)
at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:799)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:745)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:407)
at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
[EmbeddedTomcat] Ctx( /ints ): Exception in: R( /ints + /servlet/EJB + null)
java.lang.NullPointerException
at java.lang.ClassLoader.resolveClass0(Native Method)
at java.lang.ClassLoader.resolveClass(ClassLoader.java:588)
at
org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:430)
at
org.apache.tomcat.loader.AdaptiveServletLoader.loadClass(AdaptiveServletLoader.java:174)
at
org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:265)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
at org.apache.tomcat.core.Handler.service(Handler.java:254)
at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:799)
at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:745)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:210)
at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:407)
at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)

-------------------
OK, that's what happens. Now here's the rest of the story:

The war file, ints.war has this structure:
META-INF/
META-INF/MANIFEST.MF
META-INF/jboss.xml
WEB-INF/
WEB-INF/classes/
WEB-INF/classes/com/
WEB-INF/classes/com/epixtech/
WEB-INF/classes/com/epixtech/interest/
WEB-INF/classes/com/epixtech/interest/EJB.class
WEB-INF/classes/com/epixtech/interest/InterestHome.class
WEB-INF/classes/com/epixtech/interest/Interest.class
WEB-INF/classes/com/epixtech/interest/servlet/
WEB-INF/classes/com/epixtech/interest/servlet/EJB.class
WEB-INF/classes/com/epixtech/interest/ejb/
WEB-INF/classes/com/epixtech/interest/ejb/InterestHome.class
WEB-INF/classes/com/epixtech/interest/ejb/Interest.class
WEB-INF/web.xml
index.html

-----------------------------------------------------------------------
jboss.xml has:
<jboss>
<module>
<web>
<web-uri>ints.war</web-uri>
<context-root>/ints</context-root>
</web>
</module>

</jboss>

-----------------------------------------------------------------------
web.xml has:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<servlet>
<servlet-name>EJB</servlet-name>
<servlet-class>com.epixtech.interest.servlet.EJB</servlet-class>
</servlet>

</web-app>

-----------------------------------------------------------------------
index.html :
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>servlet under Tomcat under jBoss</title>
</head>
<body bgcolor="#FFFFFF">
<h1>EJB test stuff</h1>

We're getting there!

<a href="servlet/EJB">Execute the example</a><br>

</body>
</html>

------------------------------------------------------------------------
and the servlet itself, EJB.java, largely lifted from an example off the web.
Note that a stand alone command line java client program, very similar to
this, calls the ejb just fine. My problem appears more relates to TomCat
simply finding the servlet, not the servlet finding the ejb. I've been
wrong before though....

import java.io.*;

// Servlet stuff
import javax.servlet.*;
import javax.servlet.http.*;

// EJB stuff
import javax.naming.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
import com.epixtech.interest.*;

public class EJB extends HttpServlet {

public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out;
String title = "Servlet interface to EJB";

// set content type and other response header fields first
response.setContentType("text/html");

// then write the data of the response
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY bgcolor=\"#FFFFFF\">");
out.println("<H1>" + title + "</H1>");
out.println("<H2>Calling EJB...</H2>");

// Set up the naming provider; this may not always be necessary, depending
// on how your Java system is configured.
System.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
System.setProperty("java.naming.provider.url",
"localhost:1099");

try {
// Get a naming context
InitialContext jndiContext = new InitialContext();
out.println("Got context");

// Get a reference to the Interest Bean
Object ref = jndiContext.lookup("interest/Interest");
out.println("Got reference");

// Get a reference from this to the Bean's Home interface
InterestHome home = (InterestHome)
PortableRemoteObject.narrow (ref, InterestHome.class);

// Create an Interest object from the Home interface
Interest interest = home.create();
// call the calculateCompoundInterest() method to do the calculation
out.println ("Interest on 1000 units, at 10% per period, " +
"compounded over 2 periods is:");
out.println (interest.calculateCompoundInterest (1000, 0.10, 2));
} catch(Exception e) {
out.println(e.toString());
}

out.println("</BODY></HTML>");
out.close();
}
}
---------------------------------------------------------------------------

I don't know what else I can tell you.

Thanks for any help you might offer.

Ron

Jon Skeet

unread,
Feb 21, 2001, 10:24:36 AM2/21/01
to
Ron <jolt.an...@mediaone.net> wrote:
> My thanks to whomever of you can help me resolve this. This seems to
> me like one of those extremely simple errors that make you smack your
> forehead and wish you take back the question at all.
>
> OK, I'm having trouble getting a simple servlet example to work right.
>
> I suspect I have some piece of something pointing to wrong place, or
> something IN the wrong place. I'm just not up to speed enough to determine
> exactly what that might be.
>
> My setup:
> Solaris7
> java version "1.3.0"
> JSDK2.0
> JBOSS_HOME=/u/jboss_tomcat/jboss-2.0-FINAL
> TOMCAT_HOME=/u/jboss_tomcat/tomcat-3.2-b7
> using the jBoss/TomCat bundled distribution from the jBoss web site.

<snip>

The problem could well be to do with JSDK2.0. Tomcat uses servlet API
v2.2, and comes with servlet.jar. If you've already got jsdk.jar
somewhere in your classpath, that could be causing problems - rip it out
and try again.

--
Jon Skeet - sk...@pobox.com
http://www.pobox.com/~skeet

Simon Brooke

unread,
Feb 21, 2001, 12:17:42 PM2/21/01
to
on Wednesday 21 February 2001 15:15, Ron wrote:

> My thanks to whomever of you can help me resolve this. This seems to
> me like one of those extremely simple errors that make you smack your
> forehead and wish you take back the question at all.
>
> OK, I'm having trouble getting a simple servlet example to work right.
>
> I suspect I have some piece of something pointing to wrong place, or
> something IN the wrong place. I'm just not up to speed enough to
> determine exactly what that might be.

OK, you problem looks to me like your class is not in the Servlet
engine's classpath. Although the Servlet engine will load Servlets
themeselves from

webapps/yourwebapp/WEB-INF/lib

it won't load auxilliary classes from there, so the auxilliary classes
must be on the CLASSPATH which the Servlet engine uses when it starts
up. Given that you're using tomcat you can just copy the jar files
containing the classes you are using into the lib directory inside your
tomcat root directory, because the the default tomcat startup script
appends all the jars it finds there to the classpath as it starts.

--
si...@jasmine.org.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

'there are no solutions, only precipitates'


Jon Skeet

unread,
Feb 21, 2001, 12:44:20 PM2/21/01
to
Simon Brooke <si...@jasmine.org.uk> wrote:

> OK, you problem looks to me like your class is not in the Servlet
> engine's classpath. Although the Servlet engine will load Servlets
> themeselves from
>
> webapps/yourwebapp/WEB-INF/lib
>
> it won't load auxilliary classes from there, so the auxilliary classes
> must be on the CLASSPATH which the Servlet engine uses when it starts
> up.

What gives you that impression, out of interest? I'm using xerces,
xalan, javamail, all of my own classes, and various other auxiliary
libraries by putting them in the webapp lib directory. A few libraries
(JNDI for example) require you to have them in the original classpath
(for some reason I've never fathomed) but Tomcat is quite capable of
loading non-servlet classes from the webapp's lib directory.

Ron

unread,
Feb 21, 2001, 2:40:00 PM2/21/01
to
I removed JSDK2.0 from my classpath, and searched for it anywhere else
in jBoss, Tomcat, and my source/build area as well. I restarted jBoss/TomCat,
re compiled, and re-deployed. I still get:
[EmbeddedTomcat] java.lang.NoClassDefFoundError:
com/epixtech/interest/servlet/EJB (wrong name: EJB)
in the jboss log, and
Error: 500
Location: /ints/servlet/EJB
Internal Servlet Error:
java.lang.NullPointerException
at java.lang.ClassLoader.resolveClass0(Native Method)
at java.lang.ClassLoader.resolveClass(ClassLoader.java:588)
etc, etc
in the web browser.

Jon Skeet

unread,
Feb 21, 2001, 2:58:11 PM2/21/01
to
Ron <jolt.an...@mediaone.net> wrote:
> I removed JSDK2.0 from my classpath, and searched for it anywhere else
> in jBoss, Tomcat, and my source/build area as well. I restarted jBoss/TomCat,
> re compiled, and re-deployed. I still get:
> [EmbeddedTomcat] java.lang.NoClassDefFoundError:
> com/epixtech/interest/servlet/EJB (wrong name: EJB)
> in the jboss log, and
> Error: 500
> Location: /ints/servlet/EJB
> Internal Servlet Error:
> java.lang.NullPointerException
> at java.lang.ClassLoader.resolveClass0(Native Method)
> at java.lang.ClassLoader.resolveClass(ClassLoader.java:588)
> etc, etc
> in the web browser.

The "wrong name: EJB" implies that there may well be a package problem.
Does the source have a line saying
package com.epixtech.interest.servlet;
at the top? Given its location, it should have.

Ron

unread,
Feb 21, 2001, 3:11:56 PM2/21/01
to
I built a jar file including all the classes both in the "root" of
the jar, and in the full class path (com.epixtech....) and placed it in
the $TOMCAT_HOME/lib directory, and restarted jboss_with_tomcat.

Same result.

Error: 500
Location: /ints/servlet/EJB
Internal Servlet Error:
java.lang.NullPointerException
at java.lang.ClassLoader.resolveClass0(Native Method)

etc, etc
on the web browser, and

[EmbeddedTomcat] java.lang.NoClassDefFoundError:
com/epixtech/interest/servlet/EJB (wrong name: EJB)

[EmbeddedTomcat] at java.lang.ClassLoader.defineClass0(Native Method)
[EmbeddedTomcat] at
java.lang.ClassLoader.defineClass(ClassLoader.java:486)
[EmbeddedTomcat] at
org.apache.tomcat.loader.AdaptiveClassLoader12.doDefineClass(AdaptiveClassLoader12.java:93)
etc, etc

in the jboss log.

What's with this "(wrong name: EJB)" portion of the message?

Thanks,
Ron

Ron

unread,
Feb 21, 2001, 4:23:11 PM2/21/01
to
That was it. Thanks so much. Adding that one line made the whole thing
work just as I expected it to.

(Pat yourself on the back for me! :)

Ron

0 new messages