简体   繁体   English

Hibernate配置文件和Eclipse项目导出

[英]Hibernate configuration file and Eclipse project export

I have a 3 projects under Eclipse : 1-CLIENT, 2-COMMON, 3-SERVER. 我在Eclipse下有3个项目:1-客户端,2-COMMON,3-SERVER。 The server project contains everything related to database managment (ie DAO...). 服务器项目包含与数据库管理有关的所有内容(即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". 我的服务器项目还包含加载配置文件“ hibernate.cfg.xml”的HibernateUtils类。

When I run the project under Eclipse, no problem, everything is going smoothly. 当我在Eclipse下运行项目时,没问题,一切进展顺利。 Now comes the deployment... I'm exporting the server as a runnable jar file under Eclipse and the common project as a lib file. 现在开始进行部署...我正在将服务器导出为Eclipse下的可运行jar文件,并将公共项目导出为lib文件。 in the server jar file, I have the file "hibernate.cfg.xml". 在服务器jar文件中,我有文件“ 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 引起原因:org.hibernate.HibernateException:/hibernate.cfg.xml未找到

I've tried to force the filename in the configuration process using new AnnotationConfiguration().configure("XXXX/hibernate.cfg.xml") , but nothing is working ! 我尝试使用新的AnnotationConfiguration().configure("XXXX/hibernate.cfg.xml")在配置过程中强制使用文件名,但没有任何效果! 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... 即使当我复制用于启动程序的调试命令行并将其粘贴到命令dos窗口下时,它也不起作用...

What am I missing there ? 我在那里想念什么?

Hibernate searches for its configuration in places addressed in CLASS_PATH. Hibernate在CLASS_PATH中寻址的位置搜索其配置。 i suggest you put your hibernate.cfg.xml in your source folder. 我建议您将hibernate.cfg.xml放在源文件夹中。 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... 不要使用eclipse导出向导导出项目,请尝试创建一个ant文件来这样做,如果可以,请尝试maven ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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