Mik378
Mik378

Reputation: 22171

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

I wonder why Java webapps specifications imposed a specific directory for dependencies: /WEB-INF/lib.

Indeed, why don't use classic /META-INF/MANIFEST.MF file?

Someone will tell that webapps are so more secure because libs are physically integrated in WAR file.

But, if we think so, we could wonder :

Why for a simple Java application (simple JAR), there's no special directory for dependencies? It could be also more secure because no risk to have a wrong classpath (modified improperly for instance) in manifest file.

Other will tell that webapp is designed to be portable, so benefit of /WEB-INF/lib is to not worry about links dependencies.

I'm curious to know your opinions on the subject.

Upvotes: 4

Views: 3322

Answers (2)

Udo Held
Udo Held

Reputation: 12538

A jar is a standard library. For normal utility jars its probably better to keep them separate. If a library has a dependency on a different library and you need that dependent library more then once you would waste space, memory and maybe incorporte problems to due different library versions.

The web application however is an application bundle. You have to make sure that everythings works so you add the required libraries.

Upvotes: 5

Will Hartung
Will Hartung

Reputation: 118593

Because the WEB-INF/lib makes for a very easy, self contained package of libraries and simplifies the entire deploy for the most common use cases.

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

That's a full boat WAR right there, and with Servlet 3.0, the web.xml is basically empty. Simple layout, trivial to create, and a stand alone artifact to work with in the end.

Upvotes: 1

Related Questions