IDEA的maven项目和eclipse的maven项目不同。eclipse下的maven项目中,src/main/java目录下不仅可以放置.java源文件,还可以放置其他的资源文件,如*..hbm.xml文件等等。
而在Idea下的maven项目,src/main/java下只能放置.java源文件,其他资源文件必须放在src/main/resources目录下,比如spring配置文件、hibernate配置文件、.properties文件等。
像Hibernate的配置文件hbm.xml,如果你想和实体一起放到src/main.java目录下,需要在pom文件中进行配置,否则无法发布,允许时报错:Caused by: java.io.FileNotFoundException: class path resource [example/entity/UserInfo.hbm.xml] cannot be opened because it does not exist
解决方案:
pom文件build节点下增加如下配置:
<resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <excludes> <exclude>**/*.java</exclude> </excludes> <filtering>false</filtering> </resource> </resources>
includes:发布需包含
excludes:发布不包含