2014-07-26 125 views
0

我正在開發一個小的Java應用程序來學習ORM。而且應用程序僅在默認包中運行。當我將它移動到其他包中時,它會顯示以下錯誤。我想知道我怎麼能打動我的文件(hibernate.cfg.xml中,Employee.hbm.xml,Employee.java,ManageEmployee.java)使用Java,Hibernate和mySql

**log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). 
log4j:WARN Please initialize the log4j system properly. 
Failed to create sessionFactory object.org.hibernate.HibernateException: /hibernate.cfg.xml not found 
Exception in thread "main" java.lang.ExceptionInInitializerError 
    at employ_hibe.ManageEmployee.main(ManageEmployee.java:27) 
Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found 
    at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147) 
    at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1402) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1424) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1411) 
    at employ_hibe.ManageEmployee.main(ManageEmployee.java:24) 
Java Result: 1** 
+0

您是否嘗試過創建並添加'hibernate.cfg.xml'? –

回答

1

把hibernate.cfg.xml應該在的src/main /資源。在src中,它不會被添加到您的類路徑中以用於運行時。

如果您在Eclipse中運行項目,請不要忘記在構建路徑配置中的項目首選項中檢查src/main/resources是否未從類路徑中排除,並且確實是源文件夾。