2013-09-24 38 views
2

我在将应用程序部署到Openshift.com时遇到问题。Openshift - 没有EntityManager的持久性提供者

我想在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 

请帮忙。 谢谢。

回答

0

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

<dependency> 
    <groupId>org.eclipse.persistence</groupId> 
    <artifactId>org.eclipse.persistence.jpa</artifactId> 
    <version>2.5.1-RC3</version> 
</dependency> 
1

我用同样的问题挣扎,发现META-INF必须在src /主/资源,而不是的src/main/java来加载persistence.xml。

相关问题