Hibernate configure will not read hibernate.cfg.xml file

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

Order_Mod.jar
  -order_mod(package)
    -someclass.java
    -someclass_Where_Hibernate_Is_Run_And_Above_Line_Of_Code_Is_Called.java
    -hibernate.cfg.xml
LVL 2
ethnarchAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
try:

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

or

SessionFactory sessionFactory = new Configuration().setProperty("hibernate.show_sql", "true").configure("hibernate.cfg.xml").buildSessionFactory();
0
 
Ajay-SinghCommented:
you should keep the folder containing "order_mod" in the classpath
0
 
ethnarchAuthor Commented:
objects-
  That solved my problem thanks

Ajay-
  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?
0
 
Ajay-SinghCommented:
I am asking to keep the folder containing hibernate.cfg.xml (ie. order_mod) on the classpath
0
 
ethnarchAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.