views:

954

answers:

2

I've got an UberJar with all my java classes, but want to execute this jar with an external persistence.xml file. Per the specification, Hibernate (or any other JPA provider) looks for the persistence.xml file in any META-INF folder that's on the classpath, but I haven't been able to make this work with an UberJar. Any ideas? Is the UberJar's classloader restricted to the contents of the jar file?

+1  A: 

From the -jar command line option:

"-jar" When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored

So, it the seems the direct answer is no.

You could write your own bootstrap class that uses the usual java classpath (including your persistence.xml) and then bootstrap the UberJar, although you are probably using UberJar to avoid this...

Chris Kimpton
A: 

To follow up on how I solved this, I added the persistence.xml file and my jar to the classpath and then specified the main class. I also still had the unarchived classes in my path, which caused them to override the jar settings.

Steve Moyer