Hi all, I’m new to both these forums and Hibernate in general. I’ve got a little project working in Eclipse but not when I try and run it from an executable jar file (this is in a Java Spring Boot environment) it complains that it can’t locate the hibernate.cfg.xml file. I see that issues with the hibernate.cfg.xml not being found when SessionFactory is being set up is a fairly common occurrence, but my question here is somewhat specific and I’m hoping someone out there can help me out. I put the hibernate.cfg.xml file into main/resources and do this:
Configuration configuration = new Configuration();
configuration = new Configuration();
configuration.configure();
Which works in Eclipse. However, when I build an executable jar to run the application elsewhere, when it launches it complains:
Initial SessionFactory creation failed.org.hibernate.internal.util.config.ConfigurationException: Could not
locate cfg.xml resource [hibernate.cfg.xml] org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml]
I understand (or I think I do) that the reason for this is that the hibernate.cfg.xml isn’t getting included in the jar itself and so even when the path is defined it can’t find it but am not sure how to fix it. I think if I can get the file into the jar then it may work (maybe the classpath also needs an entry for this?) but I’m actually not sure how to do so. I feel like this probably gets done a lot and I’m missing some simple thing…can anyone help me out?