简体   繁体   中英

Eclipse dynamic web project - MappingNotFoundException

I have a Eclipse Dynamic Web Project which host a simple servlet and runs on Tomcat. I use Hibernate within - I have classes that map to database tables and hbm.xml files for them within my project. Everything works fine - I can use Hibernate from Servlet and modify database tables through classes. But now I want to move my "model" (Java classes for SQL tables and mapping files) to a separate Eclipse project so that I can use this "model" from other projects. After I specify a reference from my Web project to the "model" project, Eclipse can see the references and allows me using classes, but when I deploy and run the project on Tomcat, there are always errors like:

org.hibernate.MappingNotFoundException: resource: xxx/yyy/zzz/model/MyClassTable.hbm.xml not found

I suspect this is because I have to put classes for the model into WEB-INF directory, but I have no other idea how to do it than doing it manually. What is the correct way to configure Web Project in that case?

It needs to be in /WEB-INF/classes , not in /WEB-INF .

That said, you are supposed to put class source files and any other resources like .hbm.xml files in the project's src folder. Eclispe will then "automagically" put them in the /WEB-INF/classes . Alternatively, if you want to detach the configuration files from the project, then just put it somewhere outside the project in a fixed path and add this path to the runtime classpath of the server. In Tomcat you can manage those paths in shared.loader property of /conf/catalina.properties .

That said, you are supposed to put class source files and any other resources like .hbm.xml files in the project's src folder. Eclispe will then "automagically" put them in the /WEB-INF/classes. Alternatively, if you want to detach the configuration files from the project, then just put it somewhere outside the project in a fixed path and add this path to the runtime classpath of the server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM