-->
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.  [ 4 posts ] 
Author Message
 Post subject: Trick to finding hibernate.cfg.xml
PostPosted: Wed Sep 29, 2004 7:49 pm 
Newbie

Joined: Thu May 13, 2004 1:37 pm
Posts: 9
Hi All, Relative newbie to Hibernate. I'm using Eclipse 3 and have developed a standalone Java console application. It contains hibernate.cfg.xml in the project directory root. Everything works perfectly fine from within Eclipse.

However, when I export to a JAR and try to run it I get the following exception and log4j trace. I'm stumped. hibernate.cfg.xml is in the root of the jar as others have advised.


I've tried both of these to no avail.
Code:
// The cfg.configure(...) is MySessionFactory.java:48 in the following  trace.
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
// or alternatively with the slash
cfg.configure("/hibernate.cfg.xml");


I'm sure this a FAQ, but I'll certainly don't see the answer!

Any help is greatly appreciated.

Hibernate version: 2.1.4

Full stack trace of any exception that occurs:
net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:849)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:873)
at com.wrg.util.hibernate.MySessionFactory.currentSession(MySessionFactory.java:48)

Debug level Hibernate log excerpt:
19:37:48,591 INFO Environment:462 - Hibernate 2.1.4
19:37:48,591 INFO Environment:491 - hibernate.properties not found
19:37:48,601 INFO Environment:522 - using CGLIB reflection optimizer
19:37:48,601 INFO Configuration:872 - configuring from resource: /hibernate.cfg.xml
19:37:48,601 INFO Configuration:844 - Configuration resource: /hibernate.cfg.xml
19:37:48,601 WARN Configuration:848 - /hibernate.cfg.xml not found


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 8:11 am 
Newbie

Joined: Thu May 13, 2004 1:37 pm
Posts: 9
I should add that I'm running the app from the command line as
Code:
java -jar theapp.jar
theapp.jar has hibernate.cfg.xml in it's root.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 9:03 am 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
Code:
URL url = AnyClassInYourProject.class.getResource( "/hibernate.cfg.xml" );


should do the trick. Then just feed this to the configuration.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 9:30 am 
Newbie

Joined: Thu May 13, 2004 1:37 pm
Posts: 9
Myk wrote:
Code:
URL url = AnyClassInYourProject.class.getResource( "/hibernate.cfg.xml" );


PERFECT!! Thanks Myk. That does the trick.


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