where to place the hibernate.cfg.xml when developing with hibernate in java.

The hibernate.cfg.xml file is the configuration file for hibernate and as such it is vital for the use of hibernate. Like any other configuration file, you need to make it available within the classpath for the code to be able to use it.

This can be accomplished in different ways, depending on your project.

  • For a web-app WAR project (you are running the program in a Servlet container): placing it in WEB-INF/classes will work as files in WEB-INF/classes are visible on the classpath when app is running in container.
  • For a Maven-style project (not running the program in a Servlet container): placing it in /src/main/resources/ will work
  • For otherwise, try in the src/ directory.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s