Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasons to use WEB-INF/lib over EAR's lib?

I am having second thoughts about something I've been taking for granted. Namely, in an EAR with the following structure:

EAR
 \-- boo-ejb.jar
 \-- foo-web.war
 |    \--WEB-INF
 |          \--lib
 \--lib

.. I think I understand correctly that the WEB-INF/lib is for jars needed only by the web application and the EAR-level lib for jars needed by the ejb.jar as well. The rationale being to somehow make the dependencies clearer. However, why not just dump everything in the EAR-level lib folder ? Surely if there is a conflict of some sort we would like to know and investigate in depth. Wouldn't that be a cleaner solution and less prone to covering up a potential compatibility / dependency mismatch problem?

like image 387
Marcus Junius Brutus Avatar asked Feb 18 '23 20:02

Marcus Junius Brutus


1 Answers

You're absolutely right - it would be much clearer and less error prone to dependency mismatch.

But...

What in cases where you don't distribute your web applications within an EAR? Where would you place the libs? How would you go about distributing your webapps throughout different EARs so you would compose enterprise applications based upon a set of webapps?

WEB-INF/lib is also for jars that can contain resources only (with no classes within). Would you then put the web-oriented resources jars in EAR-level lib? I don't think so.

There are perhaps more reasons to use WEB-INF/lib over an EAR's lib, but the above two/three cases should be enough to at least convince you to re-think the strategy to manage libraries.

like image 174
Jacek Laskowski Avatar answered Mar 04 '23 14:03

Jacek Laskowski