0
votes

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.

1

1 Answers

0
votes

"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