Why do you prefer / WEB -INF / lib / META-INF / MANIFEST.MF for webapps?

I wonder why the Java Webapps specifications impose a specific directory for dependencies: /WEB-INF/lib .

In fact, why not use the classic /META-INF/MANIFEST.MF file?

Someone will say that webapps are so much safer because libs are physically integrated into the WAR file.

But, if we think so, we might wonder:

Why is there no special directory for dependencies for a simple Java application (simple JAR)? It can also be more secure because there is no risk of having the wrong class path (for example, incorrectly modified) in the manifest file.

Another would say that webapp is designed for portability, so the advantage of /WEB-INF/lib is not to worry about link dependencies.

I am curious to know your opinion on this matter.

+4
source share
2 answers

Jar is a standard library. For regular utility boxes, it is probably best to leave them separate. If the library has a dependency on another library, and you need this dependent library, then when you are wasting space, memory, and possibly including problems in different versions of the library.

However, a web application is a collection of applications. You have to make sure that everything works, so you add the necessary libraries.

+5
source

Because WEB-INF / lib creates a very simple, standalone library package and simplifies the deployment of the most common use case.

 /WEB-INF/web.xml /WEB-INF/lib/utils.jar /WEB-INF/classes/com/example/Servlet.class /page.jsp 

This is a full WAR boat right there, and with Servlet 3.0, web.xml is mostly empty. A simple layout, trivial to create and a stand-alone artifact to work at the end.

+1
source

Source: https://habr.com/ru/post/1381793/


All Articles