Java 如何告诉eclipse忽略:“在项目中找不到persistence.xml文件”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20287026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tell eclipse to ignore: "No persistence.xml file found in project"
提问by Festus Tamakloe
For my projects Necessity i regroup all the persistence.xml entries in one core project which i bind as maven dependency wherever i need.
对于我的项目 Necessity,我将所有 persistence.xml 条目重新组合到一个核心项目中,我在任何需要的地方都将其绑定为 Maven 依赖项。
The problem is that the eclipse IDE is always complaining about
问题是eclipse IDE老是报错
No persistence.xml file found in project
Is there away to keep eclipse quiet about this? Thanks
有没有办法让日食对此保持沉默?谢谢
采纳答案by Festus Tamakloe
Thanks to sionnach733who put me on the right way
感谢sionnach733让我走上正确的道路
回答by Niels Bech Nielsen
I assume it is the JPA perspective that you have configred.
我假设这是您配置的 JPA 透视图。
I just created an "empty" persistence.xml in src/main/java/META-INF. It would be seen by maven, so never gets further...It's a hack, I know, but it works...
我刚刚在 src/main/java/META-INF 中创建了一个“空的”persistence.xml。它会被 maven 看到,所以永远不会更进一步......我知道这是一个黑客,但它有效......
回答by Sionnach733
Window->Preferences->Java Persistence-> JPA-> Errors/warnings-> Project
Then change it from error to whatever you like(warning/info/ignore). You could also choose configure project specific settings if you don't want it to affect other projects
然后将其从错误更改为您喜欢的任何内容(警告/信息/忽略)。如果您不希望它影响其他项目,您还可以选择配置项目特定设置
回答by Ashley Schroder
I got rid of this by disabling the JPA facet for my Java project.
我通过禁用我的 Java 项目的 JPA 方面来摆脱这个问题。
回答by Alexander Wessel
If this error occurs on a Maven project that does not require the JPA facet, you can tell m2e not to apply the JPA activation (essentially, not to add the JPA facet during project configuration) by setting the following property in the pom.xml of the affected project:
如果这个错误发生在一个不需要JPA facet的Maven项目上,你可以通过在pom.xml中设置以下属性来告诉m2e不要应用JPA激活(本质上,在项目配置时不要添加JPA facet)受影响的项目:
<properties>
<m2e.jpa.activation>false</m2e.jpa.activation>
</properties>
If you press CTRL-SPACE
within an existing <properties>
tag, in the pom.xml source, content-assist will provide a shortcut to create the property, so you don't really have to remember the syntax, just that the content assist is there... ;)
如果您CTRL-SPACE
在现有<properties>
标签内按下,在 pom.xml 源代码中, content-assist 将提供创建属性的快捷方式,因此您不必真正记住语法,只要内容辅助就在那里......; )
After applying the property make sure to run Maven -> Update Project (Alt-F5)
on the project in question. You may have to remove the JPA facet from the affected project manually once, by using the Project Properties page.
应用该属性后,请确保Maven -> Update Project (Alt-F5)
在相关项目上运行。您可能需要使用“项目属性”页面手动从受影响的项目中删除 JPA 构面一次。
For those who wonder why m2e thinks the JPA facet needs to be added in the first place: This is handled by a JpaProjectConfigurator
class in the m2e/WTP eclipse plugin, and can be customized by implementing factet detectors (which all must extend the AbstractFacetDetector
class and registering them at the org.eclipse.m2e.wtp.facetDetectors
extension point). So the facet may get activated by a plugin you've installed, or by the default detection built into the Eclipse m2e/WTP feature, which basically looks for an existing persistence.xml
or orm.xml
file or a JPA provider library in the projects' classpath. I had this happen when a business logic artifact was depending depending on my persistence layer artifact (with workspace resolution turned on, which may be part of the problem) that had a META-INF/persistence.xml
, but the business logic artifact didn't.
对于那些想知道为什么 m2e 认为首先需要添加 JPA facet 的人:这是由JpaProjectConfigurator
m2e/WTP eclipse 插件中的一个类处理的,并且可以通过实现 factet 检测器来定制(所有这些都必须扩展AbstractFacetDetector
类并注册它们在org.eclipse.m2e.wtp.facetDetectors
扩展点)。因此,facet 可能会被您安装的插件激活,或者被 Eclipse m2e/WTP 功能内置的默认检测激活,它基本上在项目的类路径中查找现有persistence.xml
或orm.xml
文件或 JPA 提供程序库。当业务逻辑工件取决于我的持久层工件(打开工作区分辨率,这可能是问题的一部分)时,我会发生这种情况,该工件具有META-INF/persistence.xml
,但业务逻辑工件没有。
For details, see M2E-WTP/New and Noteworthy/1.0.0and The rg.eclipse.m2e.wtp.jpa.internal.configurators.JpaProjectConfigurator source code.
有关详细信息,请参阅M2E-WTP/New and Noteworthy /1.0.0和rg.eclipse.m2e.wtp.jpa.internal.configurators.JpaProjectConfigurator 源代码。
IMHO the accepted answer is no good advice, as it is wrongto just set the error severity to "Ignore", since then Eclipse won't warn on projects that areindeed JPA projects and thus have/need the JPA facet and consequentially should provide a persistence.xml
in the expected location (naming and location can be important for artifacts deployed in Java EE environments).
恕我直言接受的答案是没有好的建议,因为它是错误的,只是设定错误的严重性“忽略”,从此以后Eclipse将不会警告对项目的确实是JPA项目,从而有/需要的JPA面和必然应该提供apersistence.xml
在预期位置(命名和位置对于部署在 Java EE 环境中的工件可能很重要)。
In addition by actually configuring a non-JPA project correctly (i. e. without the superfluous JPA facet), Eclipse won't waste time running JPA validation and JPA change monitoring on the project. You might have noticed JPA Project Change Event Handler (waiting)
in the Progress view a lot (especially when having multiple JPA projects in the workspace). These no longer run for projects that don't require JPA, when the JPA facet is removed.
此外,通过正确配置非 JPA 项目(即没有多余的 JPA facet),Eclipse 不会浪费时间在项目上运行 JPA 验证和 JPA 更改监视。您可能已经JPA Project Change Event Handler (waiting)
在 Progress 视图中注意到了很多(尤其是在工作区中有多个 JPA 项目时)。当 JPA facet 被删除时,这些不再为不需要 JPA 的项目运行。
回答by bakoyaro
All of the other answers to this question deal with the issue by foolingEclipse into not complaining about the error.
这个问题的所有其他答案都是通过欺骗Eclipse 使其不抱怨错误来解决这个问题的。
The correct solution to the issue is to remove the JPA Facet from your project. You can do that by right-clicking the project in Project Explorer, select Properties from the menu. From there, go to "Project Facets", and ensure the JPA entry is unchecked. Click Apply, then OK. Go to the Project menu and select Clean. This will remove the spurious error.
该问题的正确解决方案是从项目中删除 JPA Facet。您可以通过右键单击 Project Explorer 中的项目,从菜单中选择 Properties 来实现。从那里,转到“Project Facets”,并确保未选中 JPA 条目。单击应用,然后单击确定。转到“项目”菜单并选择“清理”。这将消除虚假错误。
回答by pkm
1. go to .setting directory of the project
2. modify org.eclipse.wst.common.project.facet.core.xml
remove the following:
<installed facet="jpt.jpa" version="2.0"/>
3. Refresh the project
Cheers!!!
干杯!!!