views:

342

answers:

1

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?

+2  A: 

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.

BalusC
How to add this path in Eclipse? I do not want to put off this nice Eclipse <-> Tomcat cooperation where I can dynamically deploy projects. I do not want to interfere to Tomcat configuration. Is there a way to reference other Eclipse project so that its configuration files and classes are "automagically" put into WEB-INF/classes?
dominolog
As said, put in project's `src` folder. There where all your packages and remnant of source code are. As per the exception message, you should put the `hbm.xml` file in package `xxx.yyy.zzz.model`.
BalusC
For me this is not an acceptable solution. This creates redundancy because I need to double the code. I found that Eclipse "src linking" is what I need. It does not require copying the code, you just link to directories.
dominolog
Why do you need to double the code then? The `src` folder will at end land in `/WEB-INF/classes`. Maybe there was some ambiguity in the term `src` or source folder. Look, if you create a dynamic web project in Eclipse, you get a source folder and a web content folder. The source folder is there where you put your source code (packages, classes, etc). When Eclipse exports a WAR, they will all land in `/WEB-INF/classes`.
BalusC