How to tell eclipse to ignore: "No persistence.xml file found in project"
Asked Answered
N

8

33

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

Natural answered 29/11, 2013 at 13:33 Comment(1)
#17695958Feaze
N
67

Thanks to sionnach733 who put me on the right way

enter image description here

Natural answered 29/11, 2013 at 14:14 Comment(4)
Image no longer available.Origan
Ignoring problems is generally bad advice. See the other answers.Upsydaisy
Ignoring errors is not the same as having a sane project. See my answer below for the correct way to disable the JPA Facet.Ribeiro
Setting the severity to "Ignore" will make the warning go away in your Problems view, but it doesn't solve the underlying problem. M2E has activated the JPA facet on the project. The unneeded JPA facet will still waste resources (such as observing the project for changes that may affect the persistence unit), so it's NOT a good idea to ignore the problem. See my solution below. You want to disable the facet and tell M2E to not re-configure the JPA facet for that project, which can be done by disabling it globally on the Maven Preferences page, or per-project by setting the property I mention.Pacificism
R
16
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

Recite answered 29/11, 2013 at 13:40 Comment(5)
Check the answer of "Festus Tamakloe" to see the exact answer.Aristotle
This should be honored as the answer!Flow
I agree... Taking someone else's answer then writing an answer with the same info and self-accepting your own answer is not so nice I think. He could also have edited the screenshot into Sionnach733's answer.Shade
As I have detailed in my answer this doesn't solve the problem of the JPA facet being configured, it just prevents the error from being displayed. When using m2e (Maven) use my solution, when not using m2e, remove the JPA facet from the project (assuming your project is not a JPA project).Pacificism
This should be the accepted answer. For example, I have a project that doesn't have a persistence.xml in src/main/resources but does have one in src/test/resources (since it is up to dependent projects to configure exactly how they want to use the JPA entities declared in this project and having that file in the jar for this project creates problems for dependent projects) so removing the JPA facet doesn't seem to be the right solution here: it does use JPA for tests.Waverley
P
16

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.

Pacificism answered 3/6, 2016 at 2:5 Comment(3)
I really like this way and was giving it a try. So i set the property in the mavne-module where the error occured (its an ejb-module, while the persistence unit is located in an DataAccess-module). But even after updating the (parent-)project and all modules the error still occures. Any advise?Metzger
Does your project still get the jpa facet some other way? Check out the project properties? If the facet doesn't go away, neither will the warning, I would assume. Also I have every checkbox ticked on the Window -> Preferences -> Maven -> Java EE Intergration page. I'm not sure that makes a difference though. Otherwise, EJB artifacts do tend to freak out m2e (e. g. it does not understand classifiers like <type>ejb-client</type>), with all sorts of ill effects to workspace resolution and the resulting deployment assemblies.Pacificism
@bish: The property may not be removed automatically. You may need to manually remove the JPA facet once after adding the property in the POM. With the property in place it should no longer be re-applied when Maven -> Update Project (Alt-F5) is invoked.Pacificism
R
10

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.

Screen shot of Project Facets

Ribeiro answered 18/8, 2017 at 16:21 Comment(2)
Maven creates this facet again and again. See answer by Mr. Wessel.Rinarinaldi
This does not work. Facet selection is handled by m2e. m2e (not actually Maven itself) will re-add the JPA facet every time Maven -> Update Project (Alt-F5) is invoked, so your answer is incorrect. Funny you were compelled to downvote mine, with actually works.Pacificism
P
5

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

Polecat answered 23/7, 2015 at 4:26 Comment(1)
Please see my answer to this question for a step by step with screen shot.Ribeiro
E
0
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!!!

Ebon answered 10/9, 2019 at 2:32 Comment(0)
L
0

I have Eclipse Platform with this specifications: Version: Photon (4.8) Build id: I20180611-0500

I first check that the facet in:

  1. Right click on project
  2. Click on Properties
  3. Click on Project facets
  4. In the items list of facets search the JPA and validate id this is unchecked,
  5. after this check if the the error in the project tree persist, if yes: Right click on project and click in validate.
Lowermost answered 24/2, 2021 at 23:19 Comment(0)
I
-3

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

Interdisciplinary answered 29/11, 2013 at 13:39 Comment(1)
This doesn't help at all because eclipse is still complaining persistence-unit is expected.Natural

© 2022 - 2024 — McMap. All rights reserved.