eclipse Hibernate:类路径资源无法打开,因为它不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27816988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:18:49  来源:igfitidea点击:

Hibernate : classpath resource cannot be opened because it does not exist

javaeclipsespringhibernatemaven

提问by Sara

I have a Maven project using Spring and Hibernate. When I launch it in Eclipse using Debug As > Java Application, it works great. But once I exported it as a runnable .jar file, it gives me this error :

我有一个使用 Spring 和 Hibernate 的 Maven 项目。当我使用 Debug As > Java Application 在 Eclipse 中启动它时,它运行良好。但是一旦我将它导出为可运行的 .jar 文件,它就会给我这个错误:

class path resource [com/xxx/file.hbm.xml] cannot be opened because it does not exist

But when I open the .jar file, the file is located under /resources/com/xxx.file.hbm.xml. What did I do wrong ?

但是当我打开 .jar 文件时,该文件位于 /resources/com/xxx.file.hbm.xml 下。我做错了什么 ?

Thank you.

谢谢你。

采纳答案by Sara

I finally found a way to get it to work by specifying an absolute path instead of a relative path in my applicationcontext.xml file. In concrete terms, I changed "com/xxx/file.hbm.xml" to "/resources/com/xxx/file.hbm/xml". Thanks to duffymo for leading me to the right way.

我终于找到了一种通过在 applicationcontext.xml 文件中指定绝对路径而不是相对路径来使其工作的方法。具体来说,我将“com/xxx/file.hbm.xml”更改为“/resources/com/xxx/file.hbm/xml”。感谢 duffymo 带领我走向正确的道路。