I have an application that uses JPA and Hibernate ORM 4.3.8.
When I package this application and its dependencies into a single executable jar with one-jar and try to create an EntityManagerFactory Hibernate throws this exception:
javax.persistence.PersistenceException: Unable to build entity manager factory
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:83)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
...
Caused by: java.lang.IllegalArgumentException: File [/target/myapplication.one-jar.jar!/main/myapplication.jar] referenced by given URL [file:/target/myapplication.one-jar.jar!/main/myapplication.jar] does not exist
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:73)
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:48)
at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.buildArchiveDescriptor(AbstractScannerImpl.java:95)
at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:70)
I am using the onejar-maven-plugin version 1.4.5 to generate myapplication-one-jar.jar
I would really appreciate suggestions for ways to get around this. Here are two possible options:
- Use a tool other than one-jar to create an executable fat jar. The alternatives may have the same issue.
- Create a custom classloader similar to this, but I can not find a way to get JPA & Hibernate to use this classloader.
Thank you.
Switching from using One Jar to using Maven Shade fixed this problem although it had the downside of needing to resolve conflicting class names.