我无法修复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>
persistence.xml 文件必须添加到类路径中才能解决此问题。
尝试如下:
创建/更新目录 src/main/resources/META-INF,将 persistence.xml 文件放置在此处
运行 Maven->更新项目配置
通过在 Eclipse IDE > 属性 > Java 构建路径 > 源选项卡中右键单击您的项目,验证 src/main/resources 是否已添加到源文件夹(Java 资源)。你会在这里找到/src/main/resources。
选择 Maven->Update 项目配置或 Project->Clean
如果您构建应用程序,请检查 target//WEB-INF/classes/META-INF/persistence.xml 下的 persistence.xml 文件(或您配置类路径的方式)。
就是这样!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)