0

I'm trying to setup a Spring Boot application with openJPA and an external persistence unit jar file. But I'm stuck with the error message on Maven build:

The jar resource "lib/foo-persistence-unit-1.0.0jar" cannot be loaded.

I guess the persistence unit jar is not available during build time. Is this even possible when building a Spring Boot jar?

Dependency in pom.xml

<dependency>
        <groupId>com.example.bar</groupId>
        <artifactId>foo</artifactId>
        <version>1.0.0</version>
</dependency>

Openjpa maven plugin

<plugin>
   <groupId>org.apache.openjpa</groupId>
   <artifactId>openjpa-maven-plugin</artifactId>
   <configuration>
     <addDefaultConstructor>true</addDefaultConstructor>
     <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
     <persistenceXmlFile>src/main/resources/META-INF/persistence.xml</persistenceXmlFile>
   </configuration>
   <executions>
     <execution>
       <id>enhancer</id>
       <phase>process-classes</phase>
       <goals>
         <goal>enhance</goal>
       </goals>
     </execution>
    </executions>
    <dependencies>
       <dependency>
          <groupId>org.apache.openjpa</groupId>
          <artifactId>openjpa</artifactId>
          <version>${openjpa.version}</version>
       </dependency>
    </dependencies>
</plugin>

Persistence.xml:

<persistence-unit name="foo">
        <jar-file>lib/foo-persistence-unit-1.0.0.jar</jar-file>
        <properties>
            <property name="openjpa.DynamicEnhancementAgent" value="true"/>
            <property name="openjpa.ConnectionFactoryMode" value="managed"/>
            <property name="openjpa.QueryCache" value="false"/>
            <property name="openjpa.Log" value="DefaultLevel=TRACE, Tool=TRACE, SQL=TRACE"/>
            <property name="openjpa.TransactionMode" value="managed"/>
            <property name="openjpa.ManagedRuntime" value="auto"/>
            <property name="openjpa.Compatibility" value="QuotedNumbersInQueries=true"/>
        </properties>
    </persistence-unit>
Michel
  • 9,220
  • 13
  • 44
  • 59
  • Most answers are related to JavaEE and not to Spring Boot (just war). – Michel May 30 '17 at 11:51
  • 2
    The way this question is posted, it has nothing to do with Spring Boot as the error originates in the JPA provider, which is unable to find a referenced JAR file. The linked post covers all possible scenarios for using the `jar-file` element in `persistence.xml`, which is why this question is a duplicate of the linked post. – manish May 30 '17 at 12:18
  • @manish You're right. It has nothing to do with Spring Boot. ty! – Michel Jun 01 '17 at 05:41

0 Answers0