-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Holiday webapp goes awry due to NoClassDefFoundError
PostPosted: Mon Dec 19, 2005 4:01 pm 
Newbie

Joined: Mon Dec 19, 2005 3:38 pm
Posts: 4
I've been working on a webapp for my Dad's dental office. It is my Christmas gift to him this year. I made significant progress on the project this past weekend but then I hit a wall last night when JBoss started throwing a NoClassDefFoundError. My platform is Debian Linux using JDK 1.5.0_04. My environment is JBoss 4.0.2 + included Hibernate + Struts.

The error comes when I request an action URL. The action was working fine previously. The only changes I made between the time it worked and the time it broke was 1) I changed the underlying DB schema via the .hbm.xml files of 2 classes. 2) I added some new classes which are not referred to in any way from the offending action class.

The error is coming from my SessionManager class which is a wrapper for a Hibernate session. My Hibernate session is managed in the SessionManager in the ThreadLocal style. The ThreadLocal object and SessionFactory are instantiated in a class-scope static block. Inside the same static block I do a JNDI lookup to retrieve the Hibernate session. When I step through the code with a debugger I can see that the moment a reference to the SessionManager's static method getCurrentSession is made, the NoClassDefFoundError occurs.

This setup had been working fine for months, but now it's killing my app, there are only 6 days until Christmas, and I still have a lot of work to do! I've never had such trouble resolving ClassLoader/NoClassDefFoundErrors. I've checked my .har and the unfound class, of course, is where it should be (where it has always been). Why the ClassLoader can't find it all of a sudden is beyond me. I'm out of debugging ideas.

Please please please can someone offer advice on how to debug this problem. Time is ticking and this Santa Claus has some coding to do..

Thanks in advance to all who reply.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 5:10 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
If static initializer fails then JVM throws "NoClassDefFoundError" on the next attemt to load "dead" class. It is better to initialize stuff in context listener for this reason, it helps to debug.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 5:18 pm 
Newbie

Joined: Mon Dec 19, 2005 3:38 pm
Posts: 4
baliukas wrote:
It is better to initialize stuff in context listener for this reason, it helps to debug.


Thanks for the reply! Could you please elaborate on context listener initialization. I am unfamiliar with that approach. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 2:25 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
http://www.onjava.com/pub/a/onjava/2001 ... eners.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 3:15 pm 
Newbie

Joined: Mon Dec 19, 2005 3:38 pm
Posts: 4
baliukas wrote:
http://www.onjava.com/pub/a/onjava/2001/04/12/listeners.html


Great read, thanks. Some println debugging showed me that when jboss starts it does initialize my SessionManager class well before the hibernate session factory is bound to JNDI. Therefore, SessionManager initialization fails, and the class definition is not made, due to the fact that it looks up "java:/hibernate/SessionFactory" before the session factory is bound. However, the question still remains as to why this started happening all of a sudden.

Is it guaranteed that ServletContextListener.contextInitialized will be called at the very end of application start up? The article claims this method is called with the webapp is ready to service its first request, so I assume this is true. I'm hoping that I can get rid of the NoClassDefFoundError by initializing my SessionFactory in the contextInitialized method.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 2:58 pm 
Newbie

Joined: Mon Dec 19, 2005 3:38 pm
Posts: 4
JNDI lookups inside a ServletContextListener was key. That works, thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.