为ObjectDB部署ejb-module失败:找不到PersistenceProvider

时间:2015-06-15 20:32:13

标签: java maven ejb wildfly objectdb

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

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

我只是不知道我在这里失踪了什么。

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

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

无效项目应该是 ejb-module ,只有entitystateless bean

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

以下是工作网络应用程序的maven pom.xml (对不起,很久):

<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>

谁能看到我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

哇刚刚在SO上写这篇文章帮助我找到了我的错误:)我只需要强制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中,我最终可以无错误地部署它。谢谢大家关心:)