Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exposing resources from jar files in web applications (Tomcat7)

Some time ago I read an article what is expected to be in Servlet API 3.0. I remember I read that you can save some .jsp files in a /WEB-INF/lib/somelib.jar/META-INF/web/.jsp and this resources will be exposed to the context root of the web application.

I have just installed Tomcat7 to give it a try, but I found no documentation that I can put some web-resources in jar-files.

  • Does this feature exists in servlet api 3.0?
  • Does this feature exists in tomcat 7.0?
  • Is there another way to have jsp-files in /lib/*.jar files?
like image 590
Igor Mukhin Avatar asked Jan 19 '11 07:01

Igor Mukhin


People also ask

Can we use jar for Web application?

JAR files allow us to package multiple files in order to use it as a library, plugin, or any kind of application. On the other hand, WAR files are used only for web applications. The structure of the archives is also different. We can create a JAR with any desired structure.

Does jar file contain resources?

jar ) contain your executable classes and resource files. A jar can also contain other jar files, which is useful when your program needs some library which is packaged in a jar.

Can we deploy jar file in tomcat?

Tomcat JAR deployment options There are three recommended options to make this happen: Package the JAR file in the WEB-INF\lib folder of the Java web application; Place the JAR file in the \lib subfolder of the Apache Tomcat installation; Configure a folder for shared JAR files by editing Tomcat's common.

Where do I put JAR files in tomcat?

you can upload the . jar's to /home/tomcat/lib, which is mentioned in this doc. /home/tomcat/lib is added to Tomcat's class loader, so the . jar will be added just like when you put it under CATALINA_HOME/lib."


1 Answers

There is a feature in servlet 3.0 that allows you to package resources (images, jsp, etc.) in a JAR file. What you do is in your jar file, you create META-INF/resources and dump anything you want in there including directories for structuring your resources. What happens is that META-INF/resources will be mapped to the docroot of your web application.

When there is a clash of resource between your app and the JAR file, your apps resource will be returned. See this

Tomcat 7 supports Servlet 3 so it should support this feature

like image 109
Chuk Lee Avatar answered Sep 24 '22 03:09

Chuk Lee