-->
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: Configuration file from jar, but not hibernate.cfg.xml
PostPosted: Thu Aug 18, 2005 8:26 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
Hi,

Sorry if this is an RTFM, but it wasn't clear to me from the javadoc for org.hibernate.cfg.Configuration...

I need to read configuration properties from an XML file on the classpath, (in a jar), but a different file than hibernate.cfg.xml. Is there a way to do that?

Thanks,
Mark


Top
 Profile  
 
 Post subject: Re: Configuration file from jar, but not hibernate.cfg.xml
PostPosted: Thu Aug 18, 2005 8:49 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
ml wrote:
Hi,

Sorry if this is an RTFM, but it wasn't clear to me from the javadoc for org.hibernate.cfg.Configuration...

I need to read configuration properties from an XML file on the classpath, (in a jar), but a different file than hibernate.cfg.xml. Is there a way to do that?

Thanks,
Mark


Here is your solution:

Code:
            Configuration config = new Configuration();
               
            URL confFile = this.getClass().getResource(configFile);
            config = config.configure(confFile);


_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 8:50 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
It needs to be in your class path

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 1:26 am 
Beginner
Beginner

Joined: Wed Jul 13, 2005 2:18 pm
Posts: 44
I'm doing the same thing. Looks something like this:

Code:
      Configuration bannerConfig = new Configuration();
      SessionFactory sessionFactory;
      sessionFactory = bannerConfig.configure("/hibernate-banner.cfg.xml").buildSessionFactory();


minus the exception handling, of course. The file is, in this case, located at the root of the jar. In other words, if the jar contained the class com.lutrosis.SomeClass, the paths would look like:

Code:
jarfile.jar/com/lutrosis/SomeClass
jarfile.jar/hibernate-banner.cfg.xml

_________________
- Matt


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.