Java Maven/Eclipse:在类路径中找不到任何 META-INF/persistence.xml 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23835472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven/Eclipse: Could not find any META-INF/persistence.xml file in the classpath
提问by Andrew Martin
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:
我知道关于这个问题还有其他问题,但没有一个解决方案对我有用。我正在使用 maven 在 eclipse 中构建一个 java 项目,并且在 src/main/resource/META_INF 文件夹中有我的 persistence.xml 文件。但是当我尝试 mvn install 时,我总是收到这个错误:
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.xml 文件:
<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?
我已经尝试右键单击项目并将 META_INF 文件夹添加到构建路径,但它仍然不起作用。有任何想法吗?
采纳答案by user944849
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.
持久性文件的正确位置应该是 src/main/resources/META-INF。在问题中,您提到了 src/main/resource/META_INF。请注意,资源中应该有一个“s”,而 META-INF 中应该有一个破折号 (-),而不是下划线。这些只是问题中的错别字吗?如果没有,请修复路径,它应该可以工作。
回答by Guilherme
I put a exclude and the maven stopped to put the persistence.xml. I had to use brutal force to fix:
我放了一个排除项,maven 停下来放persistence.xml。我不得不使用野蛮的力量来修复:
<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>