The Eclipselink documentation says that I need the following entries in my pom.xml to get it with Maven:
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
...
</dependency>
<dependencies>
...
<repositories>
<repository>
<id>EclipseLink Repo</id>
<url>http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo</url>
</repository>
...
</repositories>
But when I try to use @Entity annotation NetBeans tells me, that the class cannot be found. And indeed: there is no Entity class in the javax.persistence package from Eclipselink.
How do I have to setup Eclipselink with Maven?
The eclipselink artifact doesn't provide the JPA 2.0 API, you need to add javax.persistence:
<repositories>
<repository>
<id>eclipselink</id>
<url>http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.0.0</version>
<scope>provided</scope><!-- since I'm running inside a Java EE container -->
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
<scope>provided</scope><!-- since I'm running inside a Java EE container -->
</dependency>
...
I recommend to use the non OSGI EclipseLink jar for the sake of simplicity.
Just add the following to your pom.xml.
Now these artifats are in the maven repositories, so no need to add any <repository>
<!-- JPA -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
Or if you are using a Java EE application server use org.eclipse.persistence.jpa:org.eclipse.persistence, as it doesn't include dependecies that are already on the server.
<!-- JPA for Java EE application servers -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
When I look into my local maven repository, org.eclipse.persistence:eclipselink does indeed contain the persistence api, at least for version 2.0.0-SNAPSHOT of eclipselink.
But there is another set of dependencies in the eclipselink repository that are a bit more modularized. These are the dependencies I am using in a current project:
<!-- persistence api -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<!-- jpa implementation -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.0.2</version>
<scope>provided</scope>
</dependency>
Note that scope is set to provided since I deploy to glassfish which already contains eclipselink.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With