Search code examples
javajpamaven-shade-pluginuberjar

Can I specify a JPA compliant persistence.xml file on the java command line?


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?


Solution

  • 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...