在Eclipse Maven Project中找不到persistence.xml

编程入门 行业动态 更新时间:2024-10-23 09:28:04
本文介绍了在Eclipse Maven Project中找不到persistence.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法修复 persistence.xml文件未找到 eclipse的问题,这是一个简单的测试项目(Maven Nature),用于非常基本的EJB测试,文件确实在src / main / resources / META-INF / ...这是pom.xml的内容。尝试将文件夹添加到项目的构建路径,更新maven项目。没有运气到目前为止,任何帮助将不胜感激,谢谢!

< project xmlns =http:// maven。 apache/POM/4.0.0xmlns:xsi =www.w3/2001/XMLSchema-instancexsi:schemaLocation =maven.apache/POM/4.0。 0 maven.apache/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> <依赖关系> <依赖关系> < groupId> org.eclipse.persistence< / groupId> < artifactId> javax.persistence< / artifactId> < version> 2.1.0< / version> < / dependency> <依赖关系> < groupId> org.ow2.spec.ee< / groupId> < artifactId> ow2-ejb-3.0-spec< / artifactId> < version> 1.0.13< / version> < / 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.0encoding =UTF-8?> < persistence xmlns =java.sun/xml/ns/persistence xmlns:xsi =www.w3/2001/XMLSchema-instance xsi:schemaLocation =java.sun/xml/ns/persistence java.sun/xml/ns/persistence/persistence_2_0.xsd version =2.0> < persistence-unit name =LibEEtransaction-type =JTA> < provider> org.eclipse.persistence.jpa.PersistenceProvider< / provider> < jta-data-source> jdbc / LibEE< / jta-data-source> <! - 指企业服务器中的数据源 - > < class> main.java.entities.Book< / class> <属性> < property name =eclipselink.ddl-generationvalue =drop-and-create-tables/> < property name =eclipselink.logging.levelvalue =INFO/> < / properties> < / persistence-unit> < / persistence>

解决方案

persistence.xml文件必须添加到类路径解除了这个问题。

尝试如下:

  • 创建/更新目录src / main / resources / META-INF,place persistence.xml文件在这里

  • 运行Maven->更新项目配置

  • 通过在Eclipse IDE>属性> Java构建路径>源选项卡中右键单击项目,验证src / main / resources是否已添加到源文件夹(Java Resources)。您将在这里找到/ src / main / resources。

  • 选择Maven->更新项目配置或Project-> Clean

  • 如果您构建应用程序,请检查目标// WEB-INF / classes / META-INF / persistence.xml(或如何配置您的类路径)下的persistence.xml文件。 p>

  • 就是这样!

  • I cannot fix the persistence.xml file not found eclipse problem, this is a simple test project (Maven Nature) for a very basic EJB testing, the file is indeed in src/main/resources/META-INF/... this is the pom.xml contents. Tried adding the folder to the project's build path, updating maven project. No luck so far, any help would be greatly appreciated, thanks!

    <project xmlns="maven.apache/POM/4.0.0" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache/POM/4.0.0 maven.apache/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>

    And this is the persistence.xml:

    <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="java.sun/xml/ns/persistence" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="java.sun/xml/ns/persistence java.sun/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 file MUST be added to the classpath to resovle this issue.

    Try as following:

  • Create/Update a directory src/main/resources/META-INF, place persistence.xml file here

  • Run Maven->Update project configuration

  • Verify that src/main/resources was added to source folders (Java Resources) by Right click on your project in Eclipse IDE > Properties > Java Build Path > Source tab. You will found /src/main/resources here.

  • Select Maven->Update project configuration or Project->Clean

  • If you build your applicaiton, check for persistence.xml file under target//WEB-INF/classes/META-INF/persistence.xml (or how you have configured your classpath).

  • That's it!

  • 更多推荐

    在Eclipse Maven Project中找不到persistence.xml

    本文发布于:2023-10-25 14:08:09,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1527182.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:中找   Maven   Eclipse   Project   xml

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!