Issue with Building JPA Web Project using Eclipse and Maven

JPA

Yesterday, I ran into a very strange issue with building a JPA web project using both Eclipse and Maven. The problem was that, if I built the project with Maven, GlassFish 3 would not recognize the project as a JPA project. If I built the project with Eclipse, everything would be fine.

Initially, I had the following project structure:

  • src/main/java
  • src/test/java
  • src/main/webapp
    • src/main/webapp/META-INF
    • src/main/webapp/META-INF/persistence.xml

It turned out that, building with Eclipse, META-INF folder would be placed under WEB-INF/classes in the WAR. Maven would not do so, and the resulted WAR would not work correctly. To fix this problem, just move META-INF from src/main/web/app to src/main/resources.