• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Suddenly getting java.lang.NoClassDefFoundError

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Java Gurus and Experts,

I need your help and suggestions on a strange issue I am facing. In my project sometime I am getting java.lang.NoClassDefFoundError

followded by java.lang.ClassNotFoundException

Though this Error is not consistant and not reproducable so far, below is the full stack of the Error, [ replaced the real class with com/abc/bcd/efg/ABC }


java.lang.NoClassDefFoundError: com/abc/bcd/efg/ABC
at aa.bb.cc.dd.ee.ff.ABC.BCD.TEST$TESTSubscription.processingSomething(TEST.java:502)
at aa.bb.cc.dd.ee.ff.ABC.BCD.TEST$TESTSubscription.processUpdate(TEST.java:363)
at aa.bb.cc.dd.ee.ff.ABC.BCD.TEST$TESTSubscription.processInsert(TEST.java:327)
at A.B.C.D.AbstractDataCallback.update(AbstractDataCallback.java:26)
at A.B.C.D.DefaultRawDataCallback.update(DefaultRawDataCallback.java:64)
at A.B.C.D.ServiceHandle.processData(Service.java:804)
at A.B.C.D.ServiceHandle.listen(Service.java:747)
at A.B.C.D.ServiceHandle.getSubs(Service.java:558)
at A.B.C.D.ServiceHandle.getSubs(Service.java:508)
at aa.bb.cc.dd.ee.ff.ABC.BCD.TEST$TESTSubscription$1.run(TEST.java:1091)
Caused by: java.lang.ClassNotFoundException: com/abc/bcd/efg/ABC
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)


This is surely a very strange issue, as this is not happening every time.



Thanks in advance,

With Regards,
Damodar
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Damodar Mukhopadhyay wrote:
This is surely a very strange issue, as this is not happening every time.


I would think this is thrown when certain piece of code is executed, which would be consistent when the required classes would be tried to be loaded.
This missing ABC class, is it in some jar? Is it on the class path?
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check your classpath. Mostly as maneesh pointed out, some jar has gone missing. Or probably you renamed some class. You might also want to check the import statements. I have had cases where the eclipse auto import messed up my actual imports
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gaurav Raje wrote:You might also want to check the import statements. I have had cases where the eclipse auto import messed up my actual imports


In that case, the code wouldn't compile in the first place, not throw an exception at runtime
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The classpath is fine also the class is is the jar.
The problem is not consistant, it not happening every time I run it!


Sometime the JVM is not able to find that class!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class path is fine during compile time, but during runtime it's obviously missing at least one class.
 
Gaurav Raje
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:

Gaurav Raje wrote:You might also want to check the import statements. I have had cases where the eclipse auto import messed up my actual imports


In that case, the code wouldn't compile in the first place, not throw an exception at runtime


Sorry my bad for explaining it poorly.
I was talking in particular about eclipse. Suppose if you are using a class called Date(strictly an arbitrary example) . which is present in both, java.sql.Date as well as java.util.Date. So while compile time, there are cases where, eclipse in its infinite wisdom converts the import statements from one to the other. So if you have a
Date d = new Date() // expecting to use java.util.Date, sometimes the import statement is converted to java.sql.date

Now if you have java.sql.Date on your classpath in eclipse, it shows no compilation error. And you have no idea that in reality you need the java.sql.Date on your classpath. But when you run it, without having java.sql.Date on your classpath, you get the noClassDefFoundError.
You doublecheck to ensure that java.util.Date is present.

May be it was just me who faced this issue, but its more of an IDE fault than anything else.
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I understood your explanation.
The surprising thing is, the program is not failing every time.

Its running properly, but some time it fails due to the Error!

Every time the classpath is the same.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Damodar Mukhopadhyay wrote:
Its running properly, but some time it fails due to the Error!

Every time the classpath is the same.



Where are you running it eclipse? Web-app? Rerunning on the same machine gives you the issue? More details would help ...
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I faced a similar issue in Eclipse before. Try closing the project, close Eclipse and reopen the project. It luckily did fix the 'no class found' error.
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks john, but I am not running the project from Eclipse, its running in a linux server!
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh you compile the classes using Eclipse and generating a jar and running that in linux? or something else?
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes John...
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I create the jar in Eclipse and run it in linux.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. Please check if manifest file is having class path set to all referenced jars. Ignore if you set class path else where (say the ksh where you execute the java cmd)
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I set classpath in script.

Also if I get this error and run it again it runs fine!!!
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MAGIC
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes.. its really a surprise!!!
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the com/abc/bcd/efg/ABC in a different jar file than the one which is using it - at aa.bb.cc.dd.ee.ff.ABC.BCD.TEST$TESTSubscription.processingSomething(TEST.java:502)

Is there a pattern in the failure? Like it always fails the first time and works the next time?
Does it always work when you run it from your IDE?

Error like NoClassDefFoundError are always a bit tricky to understand specially when they happen inconsistently... but the reason for NoClassDefFoundError this is that its not finding the class on the classpath
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its in a same and single jar, other supportive jars to that project are in classpath.

No such pattern found, but when that particular class called first time the Error comes. [and not every time actually]



 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you by any chance using reflection to load any class?

, but when that particular class called first time the Error comes. [and not every time actually]



Also the way you say that gives the impression that your program continues to work even after getting the error ... does it? You handle that condition in code?
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are reflections, but the class I am getting Error is created directly from the program it self.

And NO.. let me explain please,
Say a.b.c.d.TheClass is called from a.b.c.e.MainClass where sometime I am getting the Error.

After this error the JVM goes down, and when I restart it, all work fine!!!


 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I observed that, if the JVM is running and I redeploy the jar, and then if the JVM requires to load a class, its throwing this Error.

Is this an expected behaviour?
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by re-deploy the jar when the JVM is running? How do you do that?
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servers like Apache Tomcat allow you to overwrite a JAR file with a new version. That doesn't mean the new JAR file will automatically be used though, you still need to restart Tomcat.
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Sam
When the JVM is already running and for some time, I deployed a new version that jar.

@Rob
Thank you so much for your advice. Noted it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic