-->
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.  [ 8 posts ] 
Author Message
 Post subject: NoClassFoundException
PostPosted: Thu Sep 29, 2005 4:01 pm 
Newbie

Joined: Thu Jun 09, 2005 9:07 am
Posts: 13
Hi,

I'm trying to make Hibernate 3.0 work with struts on Eclipse 3.1 with Exadel Studio 3.0.

I included every .jar in the lib directory + hibernate3.jar into my project.

I followed the tutorial(I didn't touch my build.xml which is more populated than what the tutorial shown...not sure if everything in the tutorial's xml is in my own build.xml...does it matter?) and everything compiled but when I try to save my object by calling my 'sauvegarder' method, I get this message:

java.lang.NoClassDefFoundError: org/hibernate/Session

Session is supposed to be in hibernate3.jar which is included and deployed too in my project. Only difference with the tutorial for the initialisation part is ThreadLocal that I made generic with <Session> because I'm using JDK 1.5 and I was getting a warning without it


Here's how I coded my hibernate manager:

package HibernateManagement;


import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;

public class HibernateManager {

public static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal<Session> session = new ThreadLocal<Session>();
/**
*
* @return
* @throws HibernateException
*/
public static Session currentSession() throws HibernateException {
Session s = session.get();
// Open a new Session, if this thread has none yet
if (s == null) {
s = sessionFactory.openSession();
// Store it in the ThreadLocal variable
session.set(s);
}
return s;
}
/**
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
if (s != null)
s.close();
session.set(null);
}
/**
*
* @param objToSave
*/
public static void sauvegarder(Object objToSave) {
Session session = currentSession();
Transaction tx = session.beginTransaction();

session.saveOrUpdate(objToSave);

tx.commit();
closeSession();
}
}

Any idea what's wrong?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 4:22 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
Post the content of your WEB-INF/lib

Also, where did you put the hibernate3.jar?

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 4:32 pm 
Newbie

Joined: Thu Jun 09, 2005 9:07 am
Posts: 13
vgiguere wrote:
Post the content of your WEB-INF/lib

Also, where did you put the hibernate3.jar?


Every hibernate .jar in Hibernate's lib directory I copied into a directory named Hibernate3.0 under the lib directory of my project and I added them into the Java Build Path/library

I also put the hibernate3.jar into that directory and I added it the same way.

Beside Hibernate's .jar, there is also the commons, struts, jakarta and standard .jar into my project's lib.

added to the build path are the JRE 1.5.0_1 and 1.5.0_4 and the web app libraries.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 4:48 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
It looks to me like you have modified your build path, but that you forgot to inform your web application construction build that it needs to copy over evey lib under lib/hibernate3.0

What I understand is that you have put Hibernate's lib under a directory called hibernate3.0, that this directory is under your lib directory and this is in the Build Path/library.

Since you compile, it appears that you did this correctly. But I guess that somewhere along the way, at one point, your build tries to create a web application out of your project and it needs to copy over these hibernate jars under WEB-INF/lib.

Since you are getting a runtime noClassDefFound, it appears that this is not happening.

I am trying to see of the hibernate3.jar gets copied over properly in your web application structure. Please list the content of the WEB-INF/lib directory. It will be a lot easier to debug if we see that it is not there.

I Hope that this will help,

Vincent.

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 9:42 pm 
Newbie

Joined: Thu Jun 09, 2005 9:07 am
Posts: 13
vgiguere wrote:
It looks to me like you have modified your build path, but that you forgot to inform your web application construction build that it needs to copy over evey lib under lib/hibernate3.0

What I understand is that you have put Hibernate's lib under a directory called hibernate3.0, that this directory is under your lib directory and this is in the Build Path/library.

Since you compile, it appears that you did this correctly. But I guess that somewhere along the way, at one point, your build tries to create a web application out of your project and it needs to copy over these hibernate jars under WEB-INF/lib.

Since you are getting a runtime noClassDefFound, it appears that this is not happening.

I am trying to see of the hibernate3.jar gets copied over properly in your web application structure. Please list the content of the WEB-INF/lib directory. It will be a lot easier to debug if we see that it is not there.

I Hope that this will help,

Vincent.


The directory is listed under WEB-INF/lib also

WEB-INF/lib/Hibernate3.0
/hibernate3.jar
/ant-1.6.3.jar
/ant-antlr-1.6.3.jar
/ant-junit-1.6.3.jar
/ant-launcher-1.6.3.jar
/antlr-2.7.5H3.jar
/ant-swing-1.6.3.jar
/asm.jar
/asm-attrs.jar
/c3p0-0.8.5.2.jar
/cglib-2.1.jar
/cleanimports.jar
/commons-collections-2.1.1.jar
/commons-logging-1.0.4.jar
/concurrent-1.3.2.jar
/connector.jar
/dom4j-1.6.jar
/ehcache-1.1.jar
/hibernate3.jar
/jaas.jar
/jacc-1_0-fr.jar
/jaxen-1.1-beta-4.jar
/jboss-cache.jar
/jboss-common.jar
/jboss-jmx.jar
/jboss-system.jar
/jdbc2_0-stdext.jar
/jgroups-2.2.7.jar
/jta.jar
/junit-3.8.1.jar
/log4j-1.2.9.jar
/oscache-2.1.jar
/proxool-0.8.3.jar
/swarmcache-1.0rc2.jar
/versioncheck.jar
/xerces-2.6.2.jar
/xml-apis.jar

Those are there too:

WEB-INF/lib/commons-beanutils.jar
WEB-INF/lib/commons-collections.jar
WEB-INF/lib/commons-digesters.jar
WEB-INF/lib/commons-fileupload.jar
WEB-INF/lib/commons-lang.jar
WEB-INF/lib/commons-logging.jar
WEB-INF/lib/commons-validator.jar
WEB-INF/lib/jakarta-oro.jar
WEB-INF/lib/jstl.jar
WEB-INF/lib/standard.jar
WEB-INF/lib/struts.jar
WEB-INF/lib/struts-legacy.jar


Maybe I must not put them into a folder after all?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 9:49 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Have you tried? I mean, this is really obvious, isn't it?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 9:58 pm 
Newbie

Joined: Thu Jun 09, 2005 9:07 am
Posts: 13
christian wrote:
Have you tried? I mean, this is really obvious, isn't it?


No, it's not obvious, a jar is supposed to be a stand alone item; As long as it's included in the class path, it should work.

I'll try that anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 10:28 am 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
Yes, this is exactly what you need to do:

Everything that is currently under WEB-INF/lib/hibernate3.0 should be in WEB-INF/lib.

Things will then work for you .

Have a nice day :)

Vincent

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.