Java 来自Ear的跨应用程序持久化文件

Java 来自Ear的跨应用程序持久化文件,java,eclipse,servlets,ear,Java,Eclipse,Servlets,Ear,我已经搜索了这个,找到了很多答案,但我仍然无法让它工作。我有一个我正在从Eclipse开发的应用程序。我正在使用: EclipseKepler、Glassfish4、Mysql 5.5.31和EclipseLink 我有一个应用程序定义为 Ear project EJB project | - META-INF | - persistence.xml web project | - servlets etc 我的persis

我已经搜索了这个,找到了很多答案,但我仍然无法让它工作。我有一个我正在从Eclipse开发的应用程序。我正在使用:

EclipseKepler、Glassfish4、Mysql 5.5.31和EclipseLink

我有一个应用程序定义为

Ear project

EJB project
   |
    - META-INF
         |
          - persistence.xml

web project
   |
    - servlets etc
我的persistence.xml文件是:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="mazeEJB">
        <jta-data-source>MazeDbRes</jta-data-source>
        <class>mazeJPA.User</class>
        <class>mazeJPA.Agegroup</class>
        <class>mazeJPA.Gender</class>
        <class>mazeJPA.Maze</class>
        <properties>
            <property name="eclipselink.ddl-generation" value="create-tables"/>
        </properties>
    </persistence-unit>
</persistence>
我目前对persistenceunit位进行了注释,但如果我取消注释,就会得到一个错误

Cannot Deploy mazeApp
deploy is failing=Error occurred during deployment: Exception while preparing the app : Could not resolve a persistence unit corresponding to the persistence-unit-ref-name [servlets.User/em] in scope of the module called [mazeApp#mazeWeb.war]. Please verify your application.. Please see server.log for more details.
当我尝试在服务器上运行应用程序时。我在这种状态下找到的许多答案是,我应该将持久性文件放在ear中的jar文件中,或者放在ear的lib/META-INF中。我已经尝试过这个和其他一些组合,但即使它随后会部署,我在调用相关页面时也会遇到异常

我发现有点奇怪的是,我确实可以访问Users bean。我想解决这个问题,但我也考虑过为我想要访问的表创建一个bean并注入它。理论上,这应该是可行的,因为我只想调用使用实体生成的默认findAll命名查询

我还尝试查看生成的ear文件以查看其结构,但我认为Eclipse并没有像我预期的那样打包和部署它,因为我发现目录结构没有压缩。这是问题的一部分

有人能告诉我我做错了什么,为什么我不能让它工作?如果有人能够解释Eclipse修复此问题的步骤,则会更有帮助


我的web项目的构建路径上有EJB项目,如果这有什么不同的话。

我意识到这毕竟是一个构建路径问题。我将该项目放在web项目的构建路径上,但我需要将persistence.xml文件itslef添加到构建路径中。我必须右键单击persistence.xml文件并选择addtobuildpath。这在我的ejb项目的根目录下创建了一个persistence.jar文件,现在我可以毫无错误地部署到服务器上了。
Cannot Deploy mazeApp
deploy is failing=Error occurred during deployment: Exception while preparing the app : Could not resolve a persistence unit corresponding to the persistence-unit-ref-name [servlets.User/em] in scope of the module called [mazeApp#mazeWeb.war]. Please verify your application.. Please see server.log for more details.