在 persistence.xml 中使用 Maven 过滤时出现 Eclipse 错误

unz*_*rla 3 persistence filtering jar maven

我有一个使用 hibernate 的带有 JPA 的 Maven 项目。

我必须指定一个 jar 文件来加载外部类,persistence.xml位于src/main/resources/META-INF

<persistence unit name="PersistenceUnit" transaction-type="JTA"
    ...
    <jar-file>lib/${project.persistencejar}.jar</jar-file>
Run Code Online (Sandbox Code Playgroud)

使用 Maven 过滤(文件名可以根据各种 Maven 设置进行更改)。然后我指示 Maven 通过包含在pom.xml

<resources>
    <resource>
        <directory>${basedir}/src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
            <include>META-INF/persistence.xml</include>
        </includes>
    </resource>
</resources>
Run Code Online (Sandbox Code Playgroud)

跑步mvn clean install会产生可展开且工作的耳朵。

问题是:如果我在 Eclipse 项目配置中启用 JPA Facet,Eclipse 会抱怨

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.
Run Code Online (Sandbox Code Playgroud)

并且禁用它不会在每次更新时构建我的 JPA 项目(因此每次持久性发生变化时都必须运行 Maven。是否有一种解决方法可以告诉 Eclipse 在开发时在哪里可以找到该 jar?或者也许我我使用了错误的过滤方法吗?

谢谢

小智 6

如果问题仅出现在 Eclipse 的错误消息中,您可以在以下位置禁用它:

窗口->首选项->Java持久性->JPA->错误/警告->持久性单元

只需将“JAR 文件无法解析”设置为“忽略”即可