简体   繁体   中英

Hibernate configuration file and Eclipse project export

I have a 3 projects under Eclipse : 1-CLIENT, 2-COMMON, 3-SERVER. The server project contains everything related to database managment (ie DAO...). I'm using hibernate and annotation for this project to access database. The common project contains also some objects commonly used by both the Server and the Client. Some of these objects are from the database. My Server project contains as well the HibernateUtils class that load the configuration file "hibernate.cfg.xml".

When I run the project under Eclipse, no problem, everything is going smoothly. Now comes the deployment... I'm exporting the server as a runnable jar file under Eclipse and the common project as a lib file. in the server jar file, I have the file "hibernate.cfg.xml".

When I launch the program, I'm ending up with an exception

Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found

I've tried to force the filename in the configuration process using new AnnotationConfiguration().configure("XXXX/hibernate.cfg.xml") , but nothing is working ! Even when I copy the debug command line used to launch the program and paste it under a command dos window, it's not working...

What am I missing there ?

Hibernate searches for its configuration in places addressed in CLASS_PATH. i suggest you put your hibernate.cfg.xml in your source folder. this often prevent likely problems. Another suggestion! don not export your project using eclipse export wizard, try to create an ant file to do so, or maven if you can...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM