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

eclipsehibernatejavamavenspring

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 :

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 ?

Thank you.

Best Answer

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.