Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven/Eclipse: Could not find any META-INF/persistence.xml file in the classpath

I know there are other questions on SO about this issue, but none of the solutions have worked for me. I'm using maven to build a java project in eclipse, and I have my persistence.xml file in the src/main/resource/META_INF folder. But when I try to mvn install, I always get this error:

No Persistence provider for EntityManager named plasma.persistence

Looking through the console output it appears to be caused by this:

[org.hibernate.jpa.boot.internal.PersistenceXmlParser] - HHH000318: Could not find any META-INF/persistence.xml file in the classpath

Here is my persistence.xml file:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">
<persistence-unit name="plasma.persistence" transaction-type="RESOURCE_LOCAL">
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
        <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
        <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432:xxxxx"/>
        <property name="hibernate.connection.username" value="xxxxx"/>
        <property name="hibernate.connection.password" value="xxxxx"/>
        <property name="hibernate.connection.pool_size" value="5"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        <property name="hibernate.max_fetch_depth" value="5"/>
        <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
</persistence-unit>

I have tried right clicking on the project and adding the META_INF folder to the build path, and it still doesn't work. Any ideas?

like image 815
Andrew Martin Avatar asked May 23 '14 17:05

Andrew Martin


People also ask

Could not find any meta INF persistence XML file in the classpath in Maven?

You need to move persistence. xml to a location on your app server's class path. For a Maven project, that is typically in the src/main/resources folder. Check the Hibernate documentation to see if Hibernate expects the file to be in a sub-folder, or if putting it in the root of the classpath is OK.

What is persistence XML?

persistence. xml defines one or more persistence units. The following is an example persistence. xml file. <persistence> <persistence-unit name="OrderManagement"> <description>This unit manages orders and customers.


2 Answers

The proper home for the persistence file should be src/main/resources/META-INF. In the question, you mention src/main/resource/META_INF. Note, there should be an 's' in resources and a dash (-) in META-INF, not an underscore. Are those just typos in the question? If not, fix the path and it should work.

like image 192
user944849 Avatar answered Sep 30 '22 07:09

user944849


I put a exclude and the maven stopped to put the persistence.xml. I had to use brutal force to fix:

    <resources>
        <!-- After this maven stopped to put parsistence.xml-->
        <resource>
            <directory>src/main/resources/CATALINA_HOME/conf</directory>
            <excludes>
                <exclude>log4j.properties</exclude>
                <exclude>jpa_stocks.properties</exclude>
            </excludes>
        </resource>
        <!-- Brutal force to fix -->
        <resource>
            <directory>src/main/resources/META-INF</directory>
            <targetPath>META-INF</targetPath>
            <includes>
                <include>persistence.xml</include>
            </includes>
        </resource>
    </resources>
like image 40
Guilherme Avatar answered Sep 30 '22 09:09

Guilherme