【发布时间】:2014-01-21 08:59:19
【问题描述】:
我无法修复persistence.xml file not found eclipse 问题,这是一个简单的测试项目(Maven Nature),用于非常基本的 EJB 测试,该文件确实位于 src/main/resources/META-INF/... 这是pom.xml 内容。尝试将文件夹添加到项目的构建路径,更新 Maven 项目。到目前为止没有运气,任何帮助将不胜感激,谢谢!
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>LibEE</groupId>
<artifactId>LibEE</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>main.resources.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.ow2.spec.ee</groupId>
<artifactId>ow2-ejb-3.0-spec</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
这是persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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="LibEE" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/LibEE</jta-data-source> <!-- Refers to data source in Enterprise server -->
<class>main.java.entities.Book</class>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>
【问题讨论】:
-
src/main/resources 默认应该在构建路径中,但请确保 Maven 插件默认没有对其进行排除。它对我有用:/究竟是什么给了你错误? Eclipse 本身,单元测试,还是部署到服务器时?
-
这在 Eclipse 中显示,但是修改 pom.xml 似乎会带来新的错误......我猜它与 maven 相关
-
这一切都解决了吗?如果是这样,请提供您的解决方案,以便其他有相同问题的人受益。
标签: java eclipse maven jpa persistence.xml