[英]Eclipse dynamic web project - MappingNotFoundException
I have a Eclipse Dynamic Web Project which host a simple servlet and runs on Tomcat. 我有一个Eclipse动态Web项目,它托管一个简单的servlet并在Tomcat上运行。 I use Hibernate within - I have classes that map to database tables and hbm.xml files for them within my project.
我在内部使用Hibernate - 我的类在我的项目中有映射到数据库表和hbm.xml文件的类。 Everything works fine - I can use Hibernate from Servlet and modify database tables through classes.
一切正常 - 我可以使用Servlet中的Hibernate并通过类修改数据库表。 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.
但现在我想将我的“模型”(SQL表和映射文件的Java类)移动到一个单独的Eclipse项目中,以便我可以使用其他项目中的“模型”。 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:
在我从Web项目到“模型”项目指定引用之后,Eclipse可以看到引用并允许我使用类,但是当我在Tomcat上部署和运行项目时,总会出现以下错误:
org.hibernate.MappingNotFoundException: resource: xxx/yyy/zzz/model/MyClassTable.hbm.xml not found
org.hibernate.MappingNotFoundException:找不到资源:xxx / yyy / zzz / model / MyClassTable.hbm.xml
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. 我怀疑这是因为我必须将模型的类放入WEB-INF目录,但我不知道怎么做而不是手动操作。 What is the correct way to configure Web Project in that case?
在这种情况下配置Web项目的正确方法是什么?
It needs to be in /WEB-INF/classes
, not in /WEB-INF
. 它需要在
/WEB-INF/classes
,而不是在/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. 也就是说,您应该将类源文件和任何其他资源(如
.hbm.xml
文件)放在项目的src
文件夹中。 Eclispe will then "automagically" put them in the /WEB-INF/classes
. 然后Eclispe将“自动”将它们放入
/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
. 在Tomcat中,您可以在管理这些路径
shared.loader
财产/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. 也就是说,您应该将类源文件和任何其他资源(如.hbm.xml文件)放在项目的src文件夹中。 Eclispe will then "automagically" put them in the /WEB-INF/classes.
然后Eclispe将“自动”将它们放入/ 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
或者,如果要从项目中分离配置文件,则只需将其放在项目外的某个固定路径中,并将此路径添加到服务器的运行时类路径中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.