Reputation: 1314
I'm creating build scripts for an existing project. All of their EAR files are built (manually) and the way they do it is put the JAR dependencies of the WAR into the EAR lib
folder. The WEB-INF/lib
folder of the WAR files are empty. When I'm building with gradle it's putting the JAR dependencies of the WAR into WEB-INF/lib
folder and nothing in the EAR lib
folder.
It seems like either would work and further it seems (to me) that the more logical path is to put the WAR dependencies in WEB-INF/lib
. Is there a preferred or more correct way?
Upvotes: 0
Views: 521
Reputation: 2018
As you noted, either works technically, if it's consistent - assuming the EAR just consists of a single web module, all that's really necessary is to put them all in one place, since stuff in the EAR can't "see" stuff in the WAR under default Java EE class loading configuration.
Conceptually, though, you are correct - it's more elegant and cleaner to put everything used by a WAR in the WAR itself, rather than putting it in an otherwise-vacant EAR. While not a big deal now, it becomes important if you expand your application to multiple modules (web or EJB), because putting stuff in EAR/lib eliminates your ability to manage multiple dependencies across the modules. If you need one version of a library in WAR1 and a different version in WAR2, that's impossible if you're packaging everything at the EAR level.
Upvotes: 2
Reputation: 1283
If you only have one WAR file in the EAR, then I would definitely recommend using WEB-INF/lib. Further, I would recommend deploying the WAR directly without the EAR file, as that removes a layer of unnecessary complexity.
The case where you would want to put dependency JARs in the EAR is when you have multiple WAR files that need the same dependencies. Then you can save space by sharing the same dependencies with all of the WARs in the app.
Hope this helps!
Upvotes: 3