0

The story is about maven project dependencies. I have:

  • my project depends on hibernate-core:5.2.10.Final artifact which depends on hibernate-jpa-2.1-api:1.0.0.Final
  • and my project depends on javaee-api:7.0
  • hibernate-jpa-2.1-api:1.0.0.Final contains javax.persistence.* classes
  • the same javax.persistence.* classes are contained in javaee-api:7.0

Which dependency should i use in my project and with wich scope? If i leave both dependencies in final build then i will get a class-conflict. It is desirable that the application can be deployed to any JavaEE container such as Glassfish, Wildfly, JBOSS, etc.

Note that hibernate-jpa-2.1-api is not specific api for any JavaEE server and is not implementation. It is just API compile-scope dependency of hibernate-core artifact. And i don't include this dependency manually, if i choose Hibernate as JPA implementation then hibernate-jpa-2.1-api will be included in build by default.

keddok
  • 531
  • 1
  • 5
  • 15

1 Answers1

0

Seems i figured it out.

Most of the sources (for example http://www.adam-bien.com/roller/abien/entry/the_only_one_dependency_you) i learned stating that javaee-api dependency should be used only in provided scope. It's because the server implements these API's and implementations can vary. And you should never put javaee-api.jar in war or ear.

Also, wildfly server contains in standard modules set: hibernate-jpa-2.1-api-1.0.0.Final.jar. Which means that in this partical javaee container javax.persistence.* classes are provided by this library not javaee-api.jar.

keddok
  • 531
  • 1
  • 5
  • 15