1

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:

  1. Use a tool other than one-jar to create an executable fat jar. The alternatives may have the same issue.
  2. Create a custom classloader similar to this, but I can not find a way to get JPA & Hibernate to use this classloader.

Thank you.

John Cashew
  • 1,078
  • 2
  • 12
  • 28
  • Your questions mentions 'myapplication-one-jar.jar'. But the stacktrace has 'myapplication.one-jar.jar' and 'myapplication.jar'. Have you investigated that yet? – sgp15 Apr 13 '15 at 03:30
  • @sgp15 Sorry for the confusion. The jars are not really named myapplication. I tried to make the stack trace more readable by changing the name. The jars are named correctly. The one-jar solution worked perfectly until I introduced JPA/hibernate into the application. – John Cashew Apr 13 '15 at 03:45

1 Answers1

0

Switching from using One Jar to using Maven Shade fixed this problem although it had the downside of needing to resolve conflicting class names.

John Cashew
  • 1,078
  • 2
  • 12
  • 28