Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes unexplainable exception!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "unexplainable exception!!" Watch "unexplainable exception!!" New topic
Author

unexplainable exception!!

Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
This is extremely frustrating. I've been workign on an app for days now...debugging, coding, testing, running it over and over and over...without a single problem.

Today while testing, out of nowhere, I get this:

java.lang.NoClassDefFoundError

I have a servlet which calls a jar of my own, which references a class that comes w/ Hibernate called HibernateUtil - A simple utility for working w/ Hibernate. When I step through the debugger now I can step into the class I'm calling but on the first method I try to call...I get the error.

How does the CLASSPATH just "break"!!??

I'm relatively new to Java so this blows my mind (since it happened right in the middle of a demonstration to my boss.)

All of the necessary jars are *definitely* still in the /WEB-INF/lib directory and they always have been. Nothing *at all* has changed!

Any ideas?

Thanks!

-v
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Moving this to the Servlets forum.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
Originally posted by Michael Ernest:
Moving this to the Servlets forum.


Why did this get moved here? I'm not having a servlet problem. I'm having a very general problem w/ calling a library (or maybe the classpath)...be it in a servlet...a CLI app, whatever.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Firstly, no Exception is unexplainable.


All of the necessary jars are *definitely* still in the /WEB-INF/lib directory and they always have been. Nothing *at all* has changed!

Hmm. I suspect that is not true. Nothing in IT "just breaks", though sometimes errors can have a very difficult to find a reason for.

You say HibernateUtil comes with Hibernate? I don't think that is correct - it doesn't appear in any of the versions of Hibernate I have. It is mentioned as an example in the Hibernate docs, but you have to implement it.

As for classpaths in web apps. The rule is simple - all classes in WEB-INF/classes and WEB-INF/lib are on the classpath. Does the class you are missing exist in either of these directories?
[ September 09, 2005: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
I agree, what I meant was I am unable to explain it...it doesn't appear to make any sense and simply arose out of nowhere. I got hibernate working beautifully and during one of my Tomcat reboots...poof...suddenly it can't call the class.

Of course nothing just breaks...surely something caused it...I didn't think I'd have to explain what I meant by that....excuse me.

I downloaded Hibernate 3.0.5, in the distro was a class called HibernateUtil...HibernateUtil comes w/ Hibernate. I apologize for not being more specific.

As I said in my first post, the libraries are most definitely in the /web-inf/lib directory...that was the first thing I checked. I even stopped the server, dumped the entire web app, and reloaded it...just to be entirely sure I wasn't hallucinating.

Here's every detail I can think of as far as my environment.

Eclipse 3.1 + WTP
JDK 1.5
Hibernate 3.0.5
Tomcat 5.5.9

Just for the sake of it I commented everything else out in the doGet method of my servlet and simply declared variables of the types in the HibernateUtil class without actually instantiating them. That works just fine...it's not that it can't find the library or the types in it...so I'm baffled!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No need to apologise.

Where in Hibernate 3.0.5 is HibernateUtil? Its not in hibernate3.jar...
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
Originally posted by Paul Sturrock:
No need to apologise.

Where in Hibernate 3.0.5 is HibernateUtil? Its not in hibernate3.jar...



It's not integrated into the jar, it's a utility for developers to leverage...which is what I've done. It's in my own class and I've renamed it ORMUtility.

Now, if I comment the method out that calls ORMUtility and create a copy that doesn't call it, it works. So the class library is definitely in the classpath...and like I said - it was working beautifully for days. I was using hibernate against mysql, mssql 2000, and postgresql w/o a hitch.

I double-checked the hibernate required libraries list, they're all also in the /WEB-INF/lib folder and should be showing up int the classpath.
[ September 09, 2005: Message edited by: Vinnie Jenks ]
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
I'm sorry, I was mistaken. The HibernatUtil class comes w/ Caveat Emptor, the Hibernate sample app.

It's found in the src at:

\src\java\org\hibernate\ce\auction\persistence
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
>> Why did this get moved here?

Somebody made an error in judgement although this is obviously not a servlet problem so who knows why.

Anyway, how CLASSPATH can change is not a relevant question. Why? Because you should never use it. It's a mistake that was there in the beginning and it will be there forever. Use -classpath (or -cp for short) in javac or java commands.
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
Originally posted by Rick O'Shay:
>> Why did this get moved here?

Somebody made an error in judgement although this is obviously not a servlet problem so who knows why.

Anyway, how CLASSPATH can change is not a relevant question. Why? Because you should never use it. It's a mistake that was there in the beginning and it will be there forever. Use -classpath (or -cp for short) in javac or java commands.


I'm using eclipse, not compiling manually.
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
I'm completely at wits-end. I've been plugging away at this for EIGHT hours now and I cannot figure out the problem...I have to give up on hibernate (for now).

I commented out the function calling Hibernate in my class and un-commented the function (of the same name) that calls the same data w/ JDBC...and it works fine...I suppose I'm just stuck w/ it.

Thanks for the help anyhow!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well, I can see why it was moved here is because your Servlet is the one that is throwing the exception, and the whole thing with how to get jar files in the classpath for servlet containers is a bit different than just plain ol Java.

OK, with that said. NoClassDefFoundError is a classpath related issue, but mostly when the version of the class that is in the library is out of date, and doesn't match what is actually trying to be called.

Can you rebuild your jar file and redepploy and see what happens?

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
Originally posted by Mark Spritzler:
Well, I can see why it was moved here is because your Servlet is the one that is throwing the exception, and the whole thing with how to get jar files in the classpath for servlet containers is a bit different than just plain ol Java.

OK, with that said. NoClassDefFoundError is a classpath related issue, but mostly when the version of the class that is in the library is out of date, and doesn't match what is actually trying to be called.

Can you rebuild your jar file and redepploy and see what happens?

Thanks

Mark


I've actually tried that repeatedly. I cleaned & re-built the java project in eclipse and re-exported it as a jar...just like I always have w/ class libraries in eclipse.

I even copied the entire webapp into my resin 3.0.x installation and ran it...and I get the same error.

The only thing I can think of is perhaps eclipse "broke" something (i.e. fiddled w/ my classpath, screwed up the project file, etc.) I say this because the last thing I did was "clean" the project before it stopped working.

I have a tough time believing that it's the classpath *because* I can initialize types from the class library in question...I just can't call any of its methods w/o getting that error.

Also, I just went into the windows environment variable list and created a system env variable called CLASSPATH and explicitly added both the resin AND tomcat lib directories to the variable...rebooted, and tried again...it didn't make any difference.

The point still stands that I can call the library as long as I don't call a method that calls any Hibernate classes...the methods in the SAME CLASS in the SAME LIBRARY that use JDBC and do NOT use Hibernate...work just fine!

I've double, triple, quadruple-checked that the correct hibernate jars are in the /WEB-INF/lib directory. They were ALWAYS there and worked at one time.


All I can think of is; I'm getting some kind of bogus exception where there's actually another entirely different problem.

At this point I'm babbling incoherently...bummed that I might have to hand-code all of this object-mapping glue myself.
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
This is obviously a Hibernate issue...I was able to re-create the problem in an entirely different app.

The code I had trouble w/ all day was on my XP box at work...I'm now on Linux and was able to do exactly the same thing here.

When I started at work today I was only working with one class. I then added a second class, created a hibernate mapping-file for it, and attempted to select data like I did w/ the first object. Lo and behold, that's when it broke. I removed the second mapping, the second class, and took the mapping declaration out of hibernate.cfg.xml...re-compiled, re-ran, and it wouldn't "come back"...All I can get is the java.lang.NoClassDefFoundError.

Just now, on my linux box, I took a sample app I created a while ago which was only working w/ one class. I went through the whole routine of creating & mapping a second class to work with and now I'm getting the same error. I removed all traces of the second class and still can only get the java.lang.NoClassDefFoundError.

How insanely frustrating.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I feel for you Vinnie. I really do, and I know it is probably something simple that we just can't see.

Actually, thinking of it, yesterday I had an issue, that I could have spent hours on, but luckily someone was looking over my shoulder and told me what I needed to do to fix it.

Here is what happened in this case. we have our hibernate.cfg.xml file in our jar file that has the mappings. Now I deployed it on JBoss and it wouldn't work. Well it was a classpath issue, but basically on the order of jar files in the classpath. There was this other jar file that also had a hibernate.cfg.xml, and hibernate was using that one and not the one in my jar. So we removed the other jar out. Rebooted the app server, then it worked. So in order to have both jar files we have to change the name of the config file to something like retail.hibernate.cfg.xml and they won't get confused.

If that doesn't help, I hope at least it made you feel a little better that you are not the only one out there that gets really frsutrating issues.

Good Luck

Perserverence always wins out, and you learn a lot faster and more completely, just have to go through some frustration.

Mark
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
I REALLY appreciate you sticking it out and trying to help. And, you're absolutely right, I'm sure like me - you've been going through these kinds of learning pains for years.

Well, I figured it out myself after not being able to get anywhere w/ google OR the Hibernate forums (I get the vibe there that they're more interested in folks who *pay* for support

Anyhow, it was really stupid-simple and naturally I felt like a moron after discovering the problem - which was just simply a misspelling in the User.hbm.xml file!!!

I nearly whacked my desk in half w/ my head after noticing it. I changed it, refreshed everything...badda-bing badda-boom.

So, thanks again...I dunno what I'd do w/o these forums!

Now my mission is to figure out a few things that I need Hibernate to do (getting last insert ID, mapping multiple tables to one object, etc.)...I'll probably have to spring for a book though I really didn't want to have to do that just yet.

-v
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

OK, now, the lesson learned is: do you remember when you changed that file? Was it the last thing you changed before the last test? Probably not; the change probably didn't take effect until you bounced the server. Still, did you examine that file? Remember, you started this discussion saying that absolutely nothing had changed, but something really had: this file. Next time, you have to remember to do a thorough test after making a change like this -- or barring that, when something breaks, be sure to check everything you changed, even if it couldn't possibly be wrong.


[Jess in Action][AskingGoodQuestions]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

And the other is that the stupidest mistakes are the one's that end up taking the longest to figure out. Those single character errors sometimes takes days to figure out.

Back in the old old days in Pascal, in 1980, if you forgot a semi-colon, the compiler didn't tell you that, and you could spend days and not see that you forgot a semi-colon.

Mark
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
Originally posted by Ernest Friedman-Hill:
OK, now, the lesson learned is: do you remember when you changed that file? Was it the last thing you changed before the last test? Probably not; the change probably didn't take effect until you bounced the server. Still, did you examine that file? Remember, you started this discussion saying that absolutely nothing had changed, but something really had: this file. Next time, you have to remember to do a thorough test after making a change like this -- or barring that, when something breaks, be sure to check everything you changed, even if it couldn't possibly be wrong.


Obviously not...and in a perfect world I would have made one change at a time and tested each change of the code.

What happened is...it was broken for a long time, probably a few re-compiles later...but the .deployables in my eclipse WTP project wasn't refreshing w/ the latest version of my class library, even though I was re-publishing.

Either way, yes, you're right...something changed but it was very subtle and didn't surface when it should have.

-v
 
 
subject: unexplainable exception!!
 
Similar Threads
retrieving object hierarchy - many-to-one?
Hibernate Hell
Hibernate 3.0 Questions
is ThreadLocal devil in clustering environment?
Hibernate one-to-many inner join?