persistence.xml not found during maven testing

情到浓时终转凉″ 提交于 2019-12-04 03:01:01
jhumble

Just solved the same problem with a Maven/Eclipse based JPA project.

I had my META-INF directory under src/main/java with the concequence that it was not copied to the target directory before the test phase.

Moving this directory to src/main/resources solved the problem and ensured that the META-INF/persistence.xml file was present in target/classes when the tests were run.

I think that the JPA facet put my META-INF/persistence.xml file in src/main/java, which turned out to be the root of my problem.

I'm using Maven2, and I had forgotten to add this dependency in my pom.xml file:

 <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-entitymanager</artifactId>
   <version>3.4.0.GA</version>
 </dependency> 

If this is on windows, you can use sysinternal's procmon to find out if it's checking the right path.

Just filter by path -> contains -> persistence.xml. Procmon will pick up any attempts to open a file named persistenc.xml, and you can check to see the path or paths that get tried.

See here for more detail on procmon: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

I had the same problem and it wasn't that it couldn't find the persistence.xml file, but that it couldn't find the provider specified in the XML.

Ensure that you have the correct JPA provider dependancies and the correct provider definition in your xml file.

ie. <provider>oracle.toplink.essentials.PersistenceProvider</provider>

With maven, I had to install the 2 toplink-essentials jars locally as there were no public repositories that held the dependancies.

Is your persistence.xml located in scr/test/resources? Cause I was facing similar problems.

Everything is working fine as long as my persistence.xml is located in src/main/resources.

If I move persistence.xml to src/test/resources nothing works anymore.

The only helpful but sad answer is here: http://jira.codehaus.org/browse/SUREFIRE-427

Seems like it is not possible right now for unclear reasons. :-(

we got the same problem, does some tweaking on the project and finaly find following problem (more clear error description): at oracle.toplink.essentials.ejb.cmp3.persistence. PersistenceUnitProcessor.computePURootURL(PersistenceUnitProcessor.java:248)

With that information we recalled a primary rule: NO WHITE SPACES IN PATH NAMES!!!

Try this. Works for us smile. Maybe some day this will be fixed.

Hope this works for you. Good luck.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!