32

I'm using the Kundera tutorial at https://github.com/impetus-opensource/Kundera/wiki/Getting-Started-in-5-minutes. Eclipse does not find it when I create a folder META-INF at the project root and place persistence.xml in it.

I did a quick search and there was no real solution posted.

There is no valid reason why a simple file path should be difficult to configure. I'm looking for a simple answer to what should be a simple issue.

Dev
  • 13,492
  • 19
  • 81
  • 174
user1258361
  • 1,133
  • 2
  • 16
  • 25

4 Answers4

39

It shouldn't be at the project root, but directly under the source folder.

At runtime, the persistence.xml file is searched in the classpath, under META-INF. So if you want the META-INF folder to be put at the top of the compiled package tree, you need to put it at the top of the source tree. Eclipse copies every non-Java file to its output directory (bin, by default), respecting the package/folder hierarchy.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
29

Basically it has to be in your classpath(under /META-INF/). You can manually enable it in eclipse by configuring properties. If your project is maven based, then it should be automatically picked from /src/main/resources/META-INF/ folder (provided entities are under the same hood).

karthik manchala
  • 13,492
  • 1
  • 31
  • 55
vivek mishra
  • 1,162
  • 8
  • 16
13

It should be under src/main/resources directory,

The full path will be /src/main/resources/META-INF/persistence.xml

After creating the META-INF folder under resources directory and having a persistence.xml file loads the entityMangerFactory bean properly,

<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />

The above line reads the path correctly.

Lucky
  • 16,787
  • 19
  • 117
  • 151
2

If you are using Eclipse, right-click on 'src' folder, choose 'Build Path', then 'Use as Source Folder'

deldev
  • 1,296
  • 18
  • 27
  • 2
    AWW YEHAH ! Thank you it worked for me after 2 days of unbarbecueing –  Aug 25 '16 at 19:12