I have a Java EE project. The project is built using maven into an .ear archive. There is a library jar containing a JPA 2 persistence unit, which is located in the library
I won't comment on the configuration of Maven, but merely where libraries should go.
There're two main mechanisms to share libraries amongst an EAR's modules - Bundled Libraries (described in EE.8.2.1 in the Java EE 6 specification) and Installed Libraries (EE.8.2.2).
Installed Libraries are installed separately from an EAR and therefore are shared amongst many EARs on an application server.
Bundled Libraries may be installed in lib
(the default library directory), a directory specified by the library-directory
element of an EAR's deployment descriptor and/or in any directory to be referenced with the Class-Path
manifest header of a module (or a jar referenced by a module that in turn defines a transitive library).
My understanding of the Java EE 6 spec is that Class-Path
can reference any library anywhere in an EAR, but the content of the jar becomes then a non-Java EE module. It means that persistence.xml
is not considered upon deployment and potential persistence contexts defined in the file won't take effect at runtime.
In your case, persistence-unit.jar
seems to contain persistence unit configurations and to make them available to the other modules it should be placed in the lib
directory. The other two jars - shiro-core.jar
and slf4j-api.jar
- can be anywhere in the EAR (including the lib
directory for a simple deployment - no need to have Class-Path
element in any of the referencing libraries/modules).
Wrapping it up, to ease deployment have your libraries in the lib
directory unless Class-Path
is used and points to another directory. In this case, you'd rather check out whether the referencing jar file is not a Java EE jar with a persistence unit definition as it won't get deployed properly (and PUs won't be available to the modules).