wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes /hibernate.cfg.xml not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "/hibernate.cfg.xml not found" Watch "/hibernate.cfg.xml not found" New topic
Author

/hibernate.cfg.xml not found

Sahana Hegde
Ranch Hand

Joined: Jan 27, 2008
Posts: 67
Hi guys,

I have placed the hibernate file in the src of the project.
When I run a java application it works perfectly.
But when I use it in an application i get file not found error.
How should I correct it.

Thanks
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10146
    
165

As per the Hibernate Reference

The XML configuration file is by default expected to be in the root o your CLASSPATH


So do you have it at the root of the classpath?


[My Blog] [JavaRanch Journal]
Sahana Hegde
Ranch Hand

Joined: Jan 27, 2008
Posts: 67
I have the xml file in ProjectName/Webroot/WEB-INF/lib folder. I have added it in Build Path ->Libraries-> Add class folder -> ProjectName/Webroot/WEB-INF/lib.
[ October 24, 2008: Message edited by: Sahana Hegde ]
tapeshwar sharma
Ranch Hand

Joined: Mar 10, 2006
Posts: 245
Going by your description, it seems you are using eclipse.
Build path is for compilation time.
In your ant/maven script, you should make sure that the config file is put at a place where is in the classpath or the root at run time.
Sahana Hegde
Ranch Hand

Joined: Jan 27, 2008
Posts: 67
This is my build file

I tried changing it many times, looked on the net and changed it a few times.
[ October 24, 2008: Message edited by: Sahana Hegde ]
tapeshwar sharma
Ranch Hand

Joined: Mar 10, 2006
Posts: 245
I'd rather look where in the generated war/jar file, the config file is placed at.Can you find out for me ?
You can look inside the jar/war file by using winzip/winrar.
Shift+Right click on the jar -->open with -->select winrar/winzip, and then you can navigate into the folder structure.See where the config file is at.
Sahana Hegde
Ranch Hand

Joined: Jan 27, 2008
Posts: 67
Hi Prashant,

Thanks a lot for your patience and time.
I looked in the war file. It is in the path WEB-INF/lib.

Thanks
tapeshwar sharma
Ranch Hand

Joined: Mar 10, 2006
Posts: 245
So, is it working now or not?
In case it isn't, I'd give you a shortcut:
In the generated jar/war, find out where your hibernate DAO/access classes are located.Then, using winzip, add the config file to this jar, and reload in your application server.
If this works, then the problem is in your build file...you are not putting the config file in the right place.So, you;l need to correct it and then recreate the jar file.
If it doesn't work, well, let me know please.
Sahana Hegde
Ranch Hand

Joined: Jan 27, 2008
Posts: 67
Hi Prashant,

I tried putting hibernate config file manually in WEB-INF/classes folder and tried restarting the server. It worked.
I modified the build file to copy the resources to that location but that doesnt work.
tapeshwar sharma
Ranch Hand

Joined: Mar 10, 2006
Posts: 245
First of all, this is not a OR Mapping anymore.May be the Ant Forum.
Next, there can be many ways to put the xml in the right place through the ANT Script.
Eg. inside your jar target, do something like:
<fileset dir="${src.dir}">
<include name="**/*.xml"/>
</fileset>
 
GeeCON Prague 2014
 
subject: /hibernate.cfg.xml not found