Your built project does not have /src/main/resources , where maven stores files before they are created. When creating a project (suppose you build .jar -artifact) maven will do the following:
- All
.java files in src/main/java will be compiled into .class files and transferred to the jar subdirectory corresponding to their package - All files from
src/main/resources will be copied to the jar-file root
So, this file structure in your project:
src | +-main | +-java | | | +- mypackage | | | +- MyClass.java | +-resources | +- hibernate.cfg.xml
will appear in your .jar-file as follows:
project.jar | +- mypackage | | | +- MyClass.class | +- hibernate.cfg.xml
The essential point is that all files from /src/main/resources fall into the class path of your project. But since your configuration file is named hibernate.cfg.xml and located on the class path, you should be fine just by doing
Configuration conf = new Configuration(); conf.configure();
Note that configure() is called the wthout argument, so it means "Look for a file named hibernate.cfg.xml in your current class path." So try removing the argument from configure -call.
source share