0

I read that Meta-inf should be placed under src/main/resources. When I create a dynamic web project in Eclipse, I seem to get Meta-Inf placed under the webapp folder, alongside Web-Inf.

Where is the correct location for Meta-Inf? Does it have to be on the class path? I need to configure a persistence.xml file, not sure if that makes any difference whatsoever.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
smackenzie
  • 2,880
  • 7
  • 46
  • 99

1 Answers1

0

"I read that Meta-inf should be placed under src/main/resources"

Not necessarily. But you're right, it should be on the classpath. With src/main/resources, everything (with maven) in there get put on the classpath without the resources/. Keep in mind the Dynamic Web Project type is not a Maven type project (though it can easily be made so if needed).

"When I create a dynamic web project in Eclipse, I seem to get Meta-Inf placed under the webapp folder, alongside Web-Inf."

Yes that is for the Manifest, just like any other jar has. Not the META-INF for the classpath

" I need to configure a persistence.xml file"

You could manually create a META_INF and put it in the src (no main/resources unless you convert it to a maven project). BUT, the easiest way to configure JPA into your Dynamic Web Project is to:

  1. Right click on your project and go to properties.
  2. Find Project facets click it, and Select JPA
  3. There may be a link at the bottom for more configurations. Click it
  4. Depending on the JPA implementation, you should configure the implementation in this dialog accordingly.
  5. Once you're finished, you should see the META-INF in the src with the persistence.xml created for you.

See the javaee tutorial on persistence. It states:

If you package the persistence unit as a set of classes in a WAR file, persistence.xml should be located in the WAR file's WEB-INF/classes/META-INF directory.

If you open the navigator view (Windows -> show view -> navigator) you will see the build dir with the classes/META-INF/persistence.xml

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • Thanks, so I have converted to a maven project. Can I simply move meta-inf under src/main/resources, and this will get placed in the target of web-inf/classes/meta-inf during the build process? I assume this won't interfere with the manifest which can move with it? I assume I cant have 2 meta-inf folders, one for the manifest and one for everythnig else. – smackenzie Jul 29 '14 at 10:27
  • You can leave the original META-INF if you want. Maven will recreate it anyway (if you delete it). It's needed. But yeah you can just create a new META-INF in the src/main/resources _or_ in src/main/java. They both end up in the same place. It's more common to see it in the resources though – Paul Samsotha Jul 29 '14 at 11:27