使用 Maven 部署 Java Web 项目时,Hibernate 的映射文件 *.hbm.xml 没有被打包部署到目标目录下,解决方法:在 pom.xml 文件中 <build> 节点下添加以下代码:
<build>
……
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.hbm.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
……
</build>
或者:将 *.hbm.xml 映射文件放到 src/main/resources 文件夹下: