Solved

java.lang.NoClassDefFoundError  - servlet class not found.

Posted on 2006-07-19
8
9,804 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
  • 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now