File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Newbie Issue] hibernate.cfg.xml and hbm.xmls are not packaged by Maven?

 
Sebi Tamberg
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I'm very new to maven and running into some mandatory beginners problem. What I want is to maven along with hibernate. I have read and googled a lot concerning this problem of mine, however, I don't find a solution.

Here's my source dir structure:


compilation is no issue, but when I try and run the class by java -cp .... I get the error:



Obviously, the hibernate.cfg.xml was not copied into the jar. Adding it manually resolves this problem, however, after fixing this issue, the code complains about missing the mapper com.sas.bo.CW.hbm.xml. Hence, Maves does not copy any of the xml files, even though at leas one is in the appropiate resource path.

How can I make Maven include these .xmls when packaging the jar? Any advice is most welcome.

BTW, here's my pom.xml:




Thanks to all advicers in advance

Regs
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your POM may be more complicated that it needs to be, since there are a lot of defaults available, and I'm not even sure if some of the features you're requesting are actually used for the type of program you're describing. But that mostly doesn't matter.

When you build a stand-alone JAR artifact with Maven, fixed classpath resources that need to be copied into the target jar should be placed in the src/main/resources directory subtree. All files and directories in that subtree are copied by the jar plugin verbatim to the target jar. That should be all you need for a standalone app using Hibernate.
 
Sebi Tamberg
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ahh ... so easy it is and so blind am I ... sorry for that and thank you very much for your response.

I put ALL resources (hibernate.cfg.xml and mapping files *.hbm.xml) in the src/main/resources dir AND corrected the path to the mapping files given in hibernate.cfg.xml to point to the root and, voila, it works now:

src/main/resources/hibernate.cfg.xml
src/main/resources/CW.hbm.xml

with hibernate.cfg.xml =


Thanks & HAPPY NEW YEAR
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic