gpt4 book ai didi

java - 为 ObjectDB 部署 ejb 模块失败 : PersistenceProvider not found

转载 作者:行者123 更新时间:2023-11-30 08:07:45 26 4
gpt4 key购买 nike

我有两个几乎相同的项目(都是用maven创建的,都非常简单),其中一个部署没有任何问题,另一个给我一个PersistenceException:

javax.persistence.PersistenceException: JBAS011466: PersistenceProvider 'com.objectdb.jpa.Provider' not found

我只是不明白我在这里缺少什么。

工作项目是网络应用程序。我从 JPA Java EE 6 Tutorial 得到的。我有一个简单的 jsp 页面、servlet、一个数据库实体和一个实体的无状态 bean。

当我部署它时,我可以调用jsp,输入一些示例数据,这些数据将传递给servlet,然后servlet再次使用bean和相应的实体将数据写入ObjectDB数据库。简单的。

不工作项目应该是一个ejb模块,仅包含实体无状态bean.

但是当我尝试将其部署到本地 WildFly 服务器上时,出现上述错误。我还注意到,编译后的 ejb.jar 只有几千字节,而 Web 应用程序 war 文件则使用 1.4 MB。所以我猜它包含必要的 objectdb.jar 库。但我可以让 ejb.jar 包含该库。

这是我的 Maven pom.xml 工作 Web 应用程序(抱歉它很长):

<groupId>com.me</groupId>
<artifactId>ObjectDBMavenTest</artifactId>
<version>2.01.1-00001</version>
<packaging>war</packaging>

<name>ObjectDBMavenTest</name>

<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.objectdb</groupId>
<artifactId>objectdb</artifactId>
<version>2.6.1_06</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>objectdb</id>
<name>ObjectDB Repository</name>
<url>http://m2.objectdb.com</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

作为比较,工作的 ejb 项目的 pom.xml:

<groupId>com.me</groupId>
<artifactId>Database</artifactId>
<version>2.01.1-00001</version>
<packaging>ejb</packaging>

<name>Database</name>

<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.objectdb</groupId>
<artifactId>objectdb</artifactId>
<version>2.6.1_06</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>objectdb</id>
<name>ObjectDB Repository</name>
<url>http://m2.objectdb.com</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

坦率地说,我没有看到太大的区别,只是一个是 war 文件,另一个是 jar

如果有什么区别,这是我的两个 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="ObjectDBMavenTestPU" transaction-type="JTA">
<provider>com.objectdb.jpa.Provider</provider>
<properties>
<property name="javax.persistence.jdbc.url" value="$objectdb/db/guests.odb"/>
<property name="javax.persistence.jdbc.user" value="user"/>
<property name="javax.persistence.jdbc.password" value="password"/>
</properties>
</persistence-unit>
</persistence>

并且不工作

<?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="MyDatabase" transaction-type="JTA">
<provider>com.objectdb.jpa.Provider</provider>
<properties>
<property name="javax.persistence.jdbc.url" value="$objectdb/db/myDatabase.odb"/>
<property name="javax.persistence.jdbc.user" value="user"/>
<property name="javax.persistence.jdbc.password" value="password"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>

有人能看到我在这里做错了什么吗?

最佳答案

哇,只是在这里写下它,帮助我找到了我的错误:)我只需要强制 Maven 包含所有依赖项。这可以通过将以下插件包含到 pom.xml 中来完成:

<plugins>
...
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>

现在所需的 objectdb.jar 库作为 ejb.jar 的依赖项包含在内,我终于可以毫无错误地部署它。谢谢大家的关心:)

关于java - 为 ObjectDB 部署 ejb 模块失败 : PersistenceProvider not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30854468/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com