I have a Maven project with JPA using hibernate.
I had to specify a jar file to load external classes in persistence.xml located in src/main/resources/META-INF
<persistence unit name="PersistenceUnit" transaction-type="JTA"
...
<jar-file>lib/${project.persistencejar}.jar</jar-file>
using Maven filtering (the filename can change based on various Maven settings).
I instruct then Maven to filter by including in the pom.xml
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>META-INF/persistence.xml</include>
</includes>
</resource>
</resources>
and running mvn clean install produces a deployable and working ear.
The problem is: if I keep JPA Facet enabled in Eclipse project configuration, Eclipse complains that
Multiple annotations found at this line:
- JAR file "lib/${project.persistencejar}.jar" cannot be resolved
- The path to the JAR file will vary on your runtime environment. Please make sure the
specified path fits your particular environment.
and disabling it doesn't build my JPA project everytime that I update it (thus having to run Maven everytime there is a change in the persistence. Is there a workaround to tell Eclipse where he can find the jar at development time? Or maybe I am using the wrong approach to filtering?
Thank you
If the problem only in incorrect error message from Eclipse, you can disable it in
Window->Preferences->Java Persistence->JPA->Errors/Warnings->Persistence unit
Just set "Ignore" for "JAR file cannot be resolved"
I have solved it this way:
in persistence.xml substitute the whole <jar-file> tag, i.e.
<persistence-unit name="PersistenceUnit" transaction-type="JTA">
...
<!-- here is where the jar file is supposed to go -->
${importjarfile}
...
</persistence-unit>
Then include in pom.xml the property
<properties>
<!-- jar of persistence -->
<importjarfile><![CDATA[<jar-file>lib/${project.persistencejar}.jar</jar-file>]]></importjarfile>
</properties>
or alternatively in src/main/filters/profilename.properties file the line
importjarfile = <jar-file>lib/${project.persistencejar}.jar</jar-file>
In this way Eclipse won't see the jar-file tag and won't complain. At build time, maven will generate the correct persistence xml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With