1

I am using Maven 3.3.9 and created a Maven Web Project.

Recently I went through a Tutorial for configuring JPA with maven project.

Tutorial showing JPA configuration

I successfully configured Database connection using EclipseLink2.5

Now, My question is where is that I should put persistence.xml for the project.

In this above link it is mentioned as you will find persistence.xml under META-INF under src/main/java

I also checked in some other website where its mentioned that META-INF must be declared under WebApp and in order to do that one must create META-INF Folder with persistence.xml in side src/main/resource and do some changes to my pom.xml like below.

<build>
        <finalName>angular-watch</finalName>

        <plugins>
            <!-- Maven Java Compiler Plugin -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <!-- Maven War Plugin -->
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>

                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>

                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>${project.basedir}/src/main/resources</directory>
                        </resource>
                    </webResources>

                </configuration>

            </plugin>
        </plugins>

    </build>

So I tried to add below configuration in pom.xml to create a war with META-INF fall under WebApp.

After doing this I could find a duplication of META-INF from angular-watch.war\WEB-INF\classes\META-INF\persistence.xml

and also at angular-watch.war\META-INF\persistence.xml

So asking experts and guide me which is correct place to add persistence.xml for an webapplication project.

I read from Maven documentation that angular-watch.war\WEB-INF\classes\META-INF\persistence.xml is the location.

But I would like to get more information on this. "where should I put persistence.xml for the project" and which is the correct way of doing this and why

Naresh Raj
  • 297
  • 1
  • 6
  • 18
  • 2
    First follow the default folder layout which means `src/main/webapp` instead of `WebContent` ...afterwards remove the configuration from maven-war-plugin `warSourceDirectory`, `webResources` cause this is the default which is already handled by default. The `persistence.xml` should be put under `src/main/resources/META-INF/persistance.xml` which be automatically being put into the WAR file...Furthermore i have my doubts that you have read `that angular-watch.war\WEB-INF\classes\META-INF\persistence.xml is the location` ? Where did you read that? – khmarbaise Mar 30 '16 at 10:58
  • 1
    @khmarbaise here is the reference link for the question you had put forward. [Reference Link](http://stackoverflow.com/questions/13238615/two-meta-inf-folders-normal-structure?rq=1). Please correct me if I am wrong. – Naresh Raj Mar 30 '16 at 11:51

0 Answers0