Hibernate configure will not read hibernate.cfg.xml file

Posted on 2006-11-16
Last Modified: 2010-03-31
I have this line of code loading my hibernate.cfg.xml file

SessionFactory sessionFactory = new Configuration().setProperty("hibernate.show_sql", "true").configure("order_mod\\hibernate.cfg.xml").buildSessionFactory();
When i run this in my IDE Netbeans it works find however when i tried to run this from the jar file outside of the IDE through the command line java -jar order_mod.jar it gave me an error saying it could not find order_mod\\hibernate.cfg.xml

The directory of my jar file is as follows

Question by:ethnarch
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 92

Accepted Solution

objects earned 125 total points
ID: 17960384

SessionFactory sessionFactory = new Configuration().setProperty("hibernate.show_sql", "true").configure("/order_mod/hibernate.cfg.xml").buildSessionFactory();


SessionFactory sessionFactory = new Configuration().setProperty("hibernate.show_sql", "true").configure("hibernate.cfg.xml").buildSessionFactory();
LVL 23

Expert Comment

ID: 17962096
you should keep the folder containing "order_mod" in the classpath

Author Comment

ID: 17964765
  That solved my problem thanks

  I don't really understand what you mean if order_mod(the package) is inside my jar, then wouldn't that be inside the classpath?
LVL 23

Expert Comment

ID: 17964912
I am asking to keep the folder containing hibernate.cfg.xml (ie. order_mod) on the classpath

Author Comment

ID: 17967006
I still don't get it but nevermind i'll just say this

it is on the classpath according to what i layed out above in the initial question

well thankyou both for helping.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 122
by zero exception 10 69
sql import cannot be resolved jsp 3 74
Find out all repos that a user is most active on Github 1 28
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question