No Persistence provider problem with Maven
Hi,
please help me with following JPA problem:
I create an Entity class "Book.java" which maps database table "book".
Then I create class "Main.java" which persist data to MySQL database.
When I run Main class from Eclipse IDE (Run/Run as/Java application) it works fine and save data to database. But when I try to do this with maven, build fails:
- mvn compile works fine and produce BUILD SUCCESS, but
- mvn exec:java -Dexec.mainClass="com.apress.javaee6.chapter02.Main " produce following error:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:java <default-cli> on project jpamaven: An exception occured while executing the Java class. null: InvocationTargetException: No Persistence provider for EntityManager named chapter02PU
My persistence.xml file has this content:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.1">
<persistence-unit name="chapter02PU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceP rovider</provider>
<class>com.apress.javaee6.chapter02.Book</class>
<properties>
<property name="eclipselink.target-database" value="MySQL"></property>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"></property>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/chapter02db" />
<property name="javax.persistence.jdbc.user" value="root"></property>
<property name="javax.persistence.jdbc.password" value="root"></property>
<property name="eclipselink.ddl-generation" value="create-tables"></property>
<property name="eclipselink.logging.level" value="INFO"></property>
</properties>
</persistence-unit>
</persistence>
I am new in Maven, but my opinion is that problem could be with some missing dependency in pom.xml file:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.appres.javaee6</groupId>
<artifactId>jpamaven</artifactId>
<version>1.0</version>
<name>jpamaven</name>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.14</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</build>
</project>
Project structure:
jpamaven
-- src
-- -- main
-- -- -- java
-- -- -- -- com
-- -- -- -- -- apress
-- -- -- -- -- -- javaee6
-- -- -- -- -- -- -- chapter02
-- -- -- -- -- -- -- -- Book.java
-- -- -- -- -- -- -- -- Main.java
-- -- -- resources
-- -- -- -- META-INF
-- -- -- -- -- persistence.xml
-- -- test
-- -- -- java
-- -- -- resources
-- target
-- -- classes
-- -- -- com
-- -- -- -- apress
-- -- -- -- -- javaee6
-- -- -- -- -- -- chapter02
-- -- -- -- -- -- -- Book.class
-- -- -- -- -- -- -- Main.class
-- -- -- META-INF
-- -- -- -- persistence.xml
Any ideas why maven can´t build this project?
.