使用IDEA创建的maven工程,测试hibernate时候发现提示如下异常:
Exception in thread "main" org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found : com/gqzzw/hibernate/News.hbm.xml : origin(com/gqzzw/hibernate/News.hbm.xml)
查看源码这个com/gqzzw/hibernate/News.hbm.xml明明是存在的,很郁闷。查看maven的target发现的确缺少该xml文件,原来maven自动化打包时,默认只编译src/main/java中的java文件,其他的文件会被忽略。可以在pom.xml的<build>中添加:
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.tld</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
但在此建议,非java相关的资源,还是写在src/main/resources中比较好,这样条理清晰。