我正在使用Maven、Netbeans和Windows
我在“/src/main/resources/hibernate.cfg.xml”上有我的完全配置的hib.cfg.xml文件
我已经***三次确认这是事实***. This is my folder structure on Netbeans (picture)
当运行时,我得到这个:
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException:
Could not locate cfg.xml resource [/resources/hibernate.cfg.xml]
这是我的hibcfg.xml文件:
<!-- This file should be referenced in the configure() method!!! -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<! -- url -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@toshiba-pc:1521:SYSTEM</property>
<! -- username -->
<property name="hibernate.connection.username">system</property>
<!-- password -->
<property name="hibernate.connection.password">27111995</property>
<!-- database driver -->
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
</session-factory>
</hibernate-configuration>
在我的主课上,相关的台词是:
public static void main(String[] args) {
Configuration cfg = new Configuration();
cfg.configure("/resources/hibernate.cfg.xml");
...more code...
所以基本上我一直在努力绕过这个问题,但完全没有成功。任何帮助都将非常感激。
1条答案
按热度按时间disbfnqx1#
终于解决了!我的解决方案是使用System.property(“user.dir”)方法创建一个新的File对象,并将其传递给Configuration构造函数: