Solved

java.lang.NoClassDefFoundError  - servlet class not found.

Posted on 2006-07-19
8
9,913 Views
Last Modified: 2013-12-10
Hello Experts -

I get java.lang.NoClassDefFoundError when I try to run my j2ee application. A servlet called MainServlet.java is the entry point to the application and WSAD 5.0 is unable to find the .class file for the servlet and it also cannot locate the .properties file for the project. The problem started when I replaced a .jar file with a new one that I imported – I imported it in the following way:
In J2ee perspective I went to project properties by right clicking the project name and then selecting “Java build path” and then under the libraries tab I selected “Add External Jars” and selected the .jar file – After doing this I restarted the server and then rebuild the project and now I keep on getting the error. I even went to an extent where I deleted the workspace directory and imported a working .ear file with the original .jar file but no go.. The project is compiling properly as I dont see any errors flagging under the tasks tab.

Please throw some light – this is urgent.

Regards
Jignesh
0
Comment
Question by:Jigspat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 5

Expert Comment

by:jpolin1
ID: 17147203
If you have a servlet in a jar file that you want to run in your current web container, it needs to be specified in the web.xml, which is found under the WEB-INF directory in your web project, your web xml would look something like:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "file:something">

<web-app>

      <display-name>MyWebApp</display-name>
  <servlet>
    <servlet-name>MySweetServlet</servlet-name>
    <servlet-class>com.bus.myservlet.MySweetServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>MySweetServlet</servlet-name>
    <url-pattern>/sweet/MyServlet/*</url-pattern>
  </servlet-mapping>


....
</web-app>


So your build path points to the jar with the Servlet, then your <servlet-class> tag below should point to the Servlet with the complete package in the name, and your mapping describes how to hit it. Check and make sure all of that is in there properly.

0
 

Author Comment

by:Jigspat
ID: 17148287
Hi jpolin1 ,

My web.xml looks like the following:

....
<servlet>
    <servlet-name>MainServlet</servlet-name>
    <display-name>MainServlet</display-name>
    <servlet-class>com.dcx.parts.qpartret.servlets.MainServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>MainServlet</servlet-name>
  <url-pattern>/MainServlet</url-pattern>
</servlet-mapping>

Now in the browser I type the URL as  - http://localhost:9080/MainServlet and the context root for the project is a forward slash(/). This is what it always used to be. But after I replaced a .jar file with a new one - something got messed up - I am still unable to find the solution. WSAD tries to execute the MainServlet and in the init method of this servlet a call to super.init(servletConfig) is made which in turn I believe is trying to locate the properties file for the application but unable to find them. The properties file is located under the Java Source folder directly. I verifed that this Java Source folder is selected under the "Order and Export" tab of the project properties page.

This is becoming very urgent. Please help.

Thank you.
0
 
LVL 5

Expert Comment

by:jpolin1
ID: 17148310
Are you getting an exception? Could you paste that up here?
What changed in the jar file? Do you have the source?
If not you could decompile the .class file with DJ to see what is going on.

Is it trying to load the properties as a resourceStream?
0
Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

 

Author Comment

by:Jigspat
ID: 17148376
Note: The MainServlet extends DCServlet and this DCServlet.class is given to us in a .jar which we include in our java build path. Thus I cannot say whether it is trying to access the .properties file as a resourceStream.

The error is pasted as follows:

[7/20/06 13:49:06:552 EDT] 1e953a17 WebGroup      I SRVE0180I: [qpartret] [/] [Servlet.LOG]: MainServlet: init
[7/20/06 13:49:06:552 EDT] 1e953a17 SystemErr     R Cannot Locate file dealerconnect.properties
[7/20/06 13:49:06:552 EDT] 1e953a17 SystemErr     R Cannot Locate file qpartret.properties
[7/20/06 13:49:06:562 EDT] 1e953a17 ServletInstan E SRVE0100E: Did not realize  init() exception thrown by servlet MainServlet: javax.servlet.ServletException: org/apache/log4j/Layout
      at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doInit(StrictServletInstance.java:99)
      at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._init(StrictLifecycleServlet.java:147)
      at com.ibm.ws.webcontainer.servlet.PreInitializedServletState.init(StrictLifecycleServlet.java:270)
      at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.init(StrictLifecycleServlet.java:113)
      at com.ibm.ws.webcontainer.servlet.ServletInstance.init(ServletInstance.java:175)
      at javax.servlet.GenericServlet.init(GenericServlet.java:258)
      at com.ibm.ws.webcontainer.webapp.WebAppServletManager.addServlet(WebAppServletManager.java:761)
      at com.ibm.ws.webcontainer.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:257)
      at com.ibm.ws.webcontainer.webapp.WebAppServletManager.getServletReference(WebAppServletManager.java:382)
      at com.ibm.ws.webcontainer.webapp.WebApp.getServletReference(WebApp.java:589)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcherInfo.calculateInfo(WebAppRequestDispatcherInfo.java:177)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcherInfo.<init>(WebAppRequestDispatcherInfo.java:59)
      at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1415)
      at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1376)
      at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:196)
      at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
      at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
      at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:331)
      at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
      at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:432)
      at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:343)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:592)

[7/20/06 13:49:06:552 EDT] 1e953a17 SystemErr     R Cannot Locate file dealerconnect.passwords
[7/20/06 13:49:06:562 EDT] 1e953a17 WebGroup      E SRVE0020E: [Servlet Error]-[MainServlet]: Failed to load servlet: java.lang.NoClassDefFoundError: org/apache/log4j/Layout
      at com.dcx.dealerconnect.session.client.ContextManager.<init>(ContextManager.java)
      at com.dcx.dealerconnect.servlet.DCServlet.init(DCServlet.java)
      at com.dcx.parts.qpartret.servlets.MainServlet.init(MainServlet.java:221)
      at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doInit(StrictServletInstance.java:82)
      at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._init(StrictLifecycleServlet.java:147)
      at com.ibm.ws.webcontainer.servlet.PreInitializedServletState.init(StrictLifecycleServlet.java:270)
      at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.init(StrictLifecycleServlet.java:113)
      at com.ibm.ws.webcontainer.servlet.ServletInstance.init(ServletInstance.java:175)
      at javax.servlet.GenericServlet.init(GenericServlet.java:258)
      at com.ibm.ws.webcontainer.webapp.WebAppServletManager.addServlet(WebAppServletManager.java:761)
      at com.ibm.ws.webcontainer.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:257)
      at com.ibm.ws.webcontainer.webapp.WebAppServletManager.getServletReference(WebAppServletManager.java:382)
      at com.ibm.ws.webcontainer.webapp.WebApp.getServletReference(WebApp.java:589)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcherInfo.calculateInfo(WebAppRequestDispatcherInfo.java:177)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcherInfo.<init>(WebAppRequestDispatcherInfo.java:59)
      at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1415)
      at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1376)
      at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:196)
      at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
      at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
      at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:331)
      at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
      at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:432)
      at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:343)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:592)

[7/20/06 13:49:06:582 EDT] 1e953a17 WebGroup      E SRVE0026E: [Servlet Error]-[MainServlet]: java.lang.NoClassDefFoundError: org/apache/log4j/Layout
      at com.dcx.dealerconnect.session.client.ContextManager.<init>(ContextManager.java)
      at com.dcx.dealerconnect.servlet.DCServlet.init(DCServlet.java)
      at com.dcx.parts.qpartret.servlets.MainServlet.init(MainServlet.java:221)
      at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doInit(StrictServletInstance.java:82)
      at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._init(StrictLifecycleServlet.java:147)
      at com.ibm.ws.webcontainer.servlet.PreInitializedServletState.init(StrictLifecycleServlet.java:270)
      at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.init(StrictLifecycleServlet.java:113)
      at com.ibm.ws.webcontainer.servlet.ServletInstance.init(ServletInstance.java:175)
      at javax.servlet.GenericServlet.init(GenericServlet.java:258)
      at com.ibm.ws.webcontainer.webapp.WebAppServletManager.addServlet(WebAppServletManager.java:761)
      at com.ibm.ws.webcontainer.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:257)
      at com.ibm.ws.webcontainer.webapp.WebAppServletManager.getServletReference(WebAppServletManager.java:382)
      at com.ibm.ws.webcontainer.webapp.WebApp.getServletReference(WebApp.java:589)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcherInfo.calculateInfo(WebAppRequestDispatcherInfo.java:177)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcherInfo.<init>(WebAppRequestDispatcherInfo.java:59)
      at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1415)
      at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1376)
      at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:196)
      at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
      at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
      at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:331)
      at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
      at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:432)
      at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:343)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:592)



Thank you.
0
 
LVL 5

Expert Comment

by:jpolin1
ID: 17148425
If everything is compiling, then you need to have an entry in your manifest, found under META-INF folder of your web project and that needs to point to the location of the log4j jar, one can be downloaded from:

http://logging.apache.org/site/binindex.cgi

I think version 1.2.13 would work for you.

Now, you are missing some property files like you have said.  I guess the updated DCServlet requires some prop files, but let me guess, the person that wrote it told you nothing! That never happens!

If you download DJ Decompiler at http://www.download.com/DJ-Java-Decompiler/3000-2417_4-10439692.html
you can unzip the jar with DCServlet, and then, use the program above to see whats happening in the init method.
Paste the code for the init method up here and we can see where the property files should be.

Now, we don't know what should go in the prop files, so you may run into issues later on even if we do get it loaded properly.
Best thing to do would be to contact whoever gave you the updated jar and ask them what the deal is. They should have provided the property files along with the updated Jar, and directions.



0
 
LVL 5

Accepted Solution

by:
jpolin1 earned 500 total points
ID: 17148451
Ohh, but try getting and pointing to the log4j first and see if that works.
I think you are having 2 issues, prop files and the log4j jar.
Maybe the servlet can handle the missing prop files, but then chokes because its missing the log4j jar.
0
 

Author Comment

by:Jigspat
ID: 17148698
Hey jpolin1 ,

You know what - It was the log4j.jar that was not being recognized - Even though it was listed in the java build path but somehow when I physically went to the directory c:\ProgramFiles\IBM\WebShpere Studio\runtime\ee_V5 the log4j.jar was not even there - I added and and now I see the servlet executing and presenting my beautiful .jsp page. Thanks a ton - you made me look in to this.

Enjoy the points.

Regards
Jignesh Patel
0
 
LVL 5

Expert Comment

by:jpolin1
ID: 17148708
Cool bean.
0

Featured Post

Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question