3

我在将应用程序部署到 Openshift.com 时遇到问题。

我想在 Tomcat 上创建简单的 Java JPA 应用程序。应用程序在本地启动,但是当我将其部署到 Openshift.com 时出现此错误:

javax.persistence.PersistenceException: 
No Persistence provider for EntityManager named testpersist

我的 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>testradioapp</groupId>
    <artifactId>testradioapp</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>testradioapp</name>
    <repositories>
        <repository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.2-1003-jdbc4</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>        
         <dependency>  
            <groupId>javax.persistence</groupId>  
            <artifactId>persistence-api</artifactId>  
            <version>1.0</version>  
        </dependency>     
    </dependencies>
    <profiles>
        <profile>
            <!-- When built in OpenShift the 'openshift' profile will be used when 
                invoking mvn. -->
            <!-- Use this profile for any OpenShift specific customization your app 
                will need. -->
            <!-- By default that is to put the resulting archive into the 'webapps' 
                folder. -->
            <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
            <id>openshift</id>
            <build>
                <finalName>testradioapp</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.1.1</version>
                        <configuration>
                            <outputDirectory>webapps</outputDirectory>
                            <warName>ROOT</warName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

我的persistance.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="testpersist">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

        <class>pl.mirkofm.model.Author</class>
        <class>pl.mirkofm.model.Played</class>
        <class>pl.mirkofm.model.Rate</class>
        <class>pl.mirkofm.model.Song</class>
     <properties>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://xx:3306/xx" />
      <property name="javax.persistence.jdbc.user" value="xx"/>
      <property name="javax.persistence.jdbc.password" value="xx"/>
    </properties>
    </persistence-unit>
</persistence>

我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app metadata-complete="false" version="3.0"
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 <welcome-file-list>
  <welcome-file>/index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

我的应用树:

├───.openshift
│   ├───action_hooks
│   ├───config
│   ├───cron
│   │   ├───daily
│   │   ├───hourly
│   │   ├───minutely
│   │   ├───monthly
│   │   └───weekly
│   └───markers
├───.settings
├───src
│   └───main
│       ├───java
│       │   ├───META-INF
│       │   └───pl
│       │       └───mirkofm
│       │           ├───main
│       │           └───model
│       ├───resources
│       └───webapp
│           ├───images
│           └───WEB-INF
├───target
│   ├───classes
│   │   ├───META-INF
│   │   └───pl
│   │       └───mirkofm
│   │           ├───main
│   │           └───model
│   ├───m2e-wtp
│   │   └───web-resources
│   │       └───META-INF
│   │           └───maven
│   │               └───testradioapp
│   │                   └───testradioapp
│   └───test-classes
└───webapps

请帮忙。谢谢。

4

2 回答 2

2

我在同一个问题上苦苦挣扎,发现META-INF 需要位于 src/main/resources而不是 src/main/java 下才能加载persistence.xml。

于 2013-11-02T14:05:19.800 回答
1

您正在使用EclipseLink不会在类路径上的提供程序。您需要将以下内容添加到您的pom.xml文件中:

<dependency>
   <groupId>org.eclipse.persistence</groupId>
   <artifactId>org.eclipse.persistence.jpa</artifactId>
   <version>2.5.1-RC3</version>
</dependency>
于 2013-09-25T23:46:11.653 回答