繁体   English   中英

Maven EAR多模块项目未打包persistence.xml

[英]Maven EAR multimodule project not packaging persistence.xml

我正在使用带有2个模块的Maven在EAR项目中工作。 图像胜于雄辩,所以让我向您展示结构:

父pom项目和模块

pom项目和模块

sigea-model包含模型,存储库和服务层( MVC中“ M” )。 sigea-web包含网页和控制器bean( VC ),而sigea-ear只是将其他2个模块打包为EAR包的包装器。

模块中的配置文件

模块中的配置文件

如您所见, sigea-ear有一个空的META-INF文件夹。 这两个beans.xml文件中sigea-modelsigea-web都只是空的标记文件,因为据我所知,CDI在所有注释类默认搜索(但这不是现在的问题)。 persistence.xml是一个简单的文件,它通过连接池使用JTA事务(之所以起作用是因为我从Glassfish的管理控制台ping并成功)。

最后,打包应用程序时,我得到以下信息:

包装的耳朵

如您所见,没有persistence.xml 所有这些都是因为我成功部署了应用程序而出现的,但是在第一次单击中我得到了例外

          javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean
          ...
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null

这是我的pom文件:

pom.xml [sigea-app](父项目)

<project ...>
    <modelVersion>4.0.0</modelVersion>
    <groupId>ar.edu.unt.sigea</groupId>
    <artifactId>sigea-app</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <modules>
        <module>sigea-model</module>
        <module>sigea-web</module>
        <module>sigea-ear</module>
    </modules>

    <build>
        <pluginManagement>
            ...
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <!-- I suppress some lines for brevity -->
        <dependencies>
            <dependency>
                <artifactId>sigea-model</artifactId>
            </dependency>
            <dependency>
                <artifactId>sigea-model</artifactId>
                <type>ejb</type>
            </dependency>
            <dependency>
                <artifactId>sigea-model</artifactId>
                <type>test-jar</type>
                <scope>test</scope>
            </dependency>
            <dependency>
                <artifactId>sigea-web</artifactId>
                <type>war</type>
            </dependency>
            <dependency>
                <artifactId>sigea-web</artifactId>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        ...
    </dependencies>
</project>

pom.xml [sigea-ear]

<project ...>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>ar.edu.unt.sigea</groupId>
        <artifactId>sigea-app</artifactId>
        <version>1.0</version>
    </parent>

    <artifactId>sigea-ear</artifactId>
    <packaging>ear</packaging>

    <dependencies>
        <dependency>
            <artifactId>sigea-model</artifactId>
            <type>ejb</type>
        </dependency>
        <dependency>
            <artifactId>sigea-web</artifactId>
            <type>war</type>
        </dependency>
        <dependency>
            <artifactId>sigea-web</artifactId>
            <type>pom</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <configuration>
                    <defaultLibBundleDir>lib/</defaultLibBundleDir>
                    <skinnyWars>true</skinnyWars>
                    <modules>
                        <webModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>sigea-web</artifactId>
                            <contextRoot>/sigea</contextRoot>
                        </webModule>
                        <ejbModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>sigea-model</artifactId>
                        </ejbModule>
                    </modules>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

pom.xml [sigea-web]

<project ...>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>sigea-app</artifactId>
        <groupId>ar.edu.unt.sigea</groupId>
        <version>1.0</version>
    </parent>

    <groupId>ar.edu.unt.sigea</groupId>
    <artifactId>sigea-web</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>sigea-web</name>

    <dependencies>
        <!-- Some dependencies including sigea-model -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <packagingExcludes>WEB-INF/lib/*.jar</packagingExcludes>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

pom.xml[sigea-model]并不重要,因为它仅定义了一些用于测试的依赖项,并被配置为生成带有测试类的程序包,这些类也在sigea-web用于测试目的。

最后一个问题: 未打包persistence.xml文件的配置中出现了什么问题 如果那不是上面显示的消息的IllegalStateException的问题,那么该异常的可能原因是什么?

预先感谢您的回答。

我通过更改依赖关系解决了这个问题。 sigea-model我有

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.1.0.Final</version>
    <scope>test</scope>
</dependency>

我曾经用来管理测试方法的持久性上下文。 我没有t inquire very much in the Glassfish JPA provided implementation but maybe it's Eclipse Link instead of Hibernate. Apparently there are some incompatibility issue between those libraries. I moved t inquire very much in the Glassfish JPA provided implementation but maybe it's Eclipse Link instead of Hibernate. Apparently there are some incompatibility issue between those libraries. I moved t inquire very much in the Glassfish JPA provided implementation but maybe it's Eclipse Link instead of Hibernate. Apparently there are some incompatibility issue between those libraries. I moved hibernate-entitymanager`移至编译范围,如下所示:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.1.0.Final</version>
</dependency>

现在,项目编译就没有问题了。 khmarbaise的评论也很有用,它简化了项目配置,非常感谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM