How to tell eclipse to ignore: “No persistence.xml file found in project”

冷暖自知 提交于 2019-12-20 11:06:31

问题


For my projects Necessity i regroup all the persistence.xml entries in one core project which i bind as maven dependency wherever i need.

The problem is that the eclipse IDE is always complaining about

No persistence.xml  file found in project

Is there away to keep eclipse quiet about this? Thanks


回答1:


Thanks to sionnach733 who put me on the right way




回答2:


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




回答3:


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:

<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... ;)

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.

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.

For details, see M2E-WTP/New and Noteworthy/1.0.0 and The rg.eclipse.m2e.wtp.jpa.internal.configurators.JpaProjectConfigurator source code.

IMHO the accepted answer is no good advice, as it is wrong to just set the error severity to "Ignore", since then Eclipse won't warn on projects that are indeed 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).

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.




回答4:


All of the other answers to this question deal with the issue by fooling Eclipse into not complaining about the error.

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.




回答5:


I got rid of this by disabling the JPA facet for my Java project.




回答6:


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!!!




回答7:


I assume it is the JPA perspective that you have configred.

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...



来源:https://stackoverflow.com/questions/20287026/how-to-tell-eclipse-to-ignore-no-persistence-xml-file-found-in-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!