Hello,
I'm learning JEE6 and I'm also new to Maven. I'm trying to resolve this
issue for two days already with no success, so maybe someone could help me
here? The thing is, I can't run a hello world app, that uses JPA. Here's
what I do and what I get:
mvn exec:java -Dexec.mainClass="ru.hatchery.jeetest.App"
[INFO] Scanning for projects...
[INFO]
[INFO]
------------------------------------------------------------------------
[INFO] Building jeetest 1.0-SNAPSHOT
[INFO]
------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ jeetest >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ jeetest <<<
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ jeetest ---
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.persistence.PersistenceException: No Persistence provider
for EntityManager named jeetest
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:84)
at
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at ru.hatchery.jeetest.App.main(App.java:16)
... 6 more
[INFO]
------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 3.580s
[INFO] Finished at: Tue Dec 11 14:17:24 MSK 2012
[INFO] Final Memory: 8M/109M
[INFO]
------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project
jeetest: An exception occured while executing the Java class. null:
InvocationTargetException: No Persistence provider for EntityManager named
jeetest -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e
switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions,
please read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
The persistence.xml file is located in my src/main/resources/META-INF and
it's being correctly copied to target/classes/META-INF. Here is the
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun/com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="jeetest" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>ru.hatchery.jeetest.Book</class>
<properties>
<property name="eclipselink.target-database" value="DERBY"/>
<property name="eclipselink.ddl-generation"
value="create-tables"/>
<property name="eclipselink.logging.level" value="INFO"/>
<property name="javax.persistence.jdbc.driver"
value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.url"
value="jdbc:derby://localhost:1527/jeetestdb;create=true"/>
<property name="javax.persistence.jdbc.user" value="test"/>
<property name="javax.persistence.jdbc.password" value="test"/>
</properties>
</persistence-unit>
</persistence>
The database is also up and running. And here is the 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ru.hatchery</groupId>
<artifactId>jeetest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jeetest</name>
<repositories>
<repository>
<id>EclipseLink</id>
<url>http://download.eclipse.org/rt/eclipselink/maven.repo</url>
</repository>
<repository>
<id>DerbyClient</id>
<url>http://repository.apache.org/content/repositories/releases
</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.6.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Maybe I should add a dependency for that
org.eclipse.persistence.jpa.PersistenceProvider? But I don't know the
groupId, artifactId and version for it. I guess my mistake is stupid, but
I'm stuck on it. Please, give me a clue.
Thank you!
Anton Reshetnikov