Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Servlet containers and classpath

To what is the class path of a Servlet container set?

As per my understanding there are three components involved. The JAR files in the lib directory of the Servlet container and then the classes in the WEB-INF/classes and JAR files in the WEB-INF/lib directory. The classes in lib directory of the Servlet container are added to the system classpath and the dynamic classpath includes the JAR files in the lib directory and classes in the classes directory.

To what is the dynamic classpath set? Does the dynamic classpath point to all the directories under WEB-INF or includes all the individual classes and JAR files in WEB-INF/lib and WEB-INF/classes or just points to the two directories WEB-INF/classes and WEB-INF/lib? Say I have a directory called foo in WEB-INF containing bar.properties. Now is bar.properties also in the class path?

like image 997
Abhi Avatar asked Nov 20 '08 13:11

Abhi


People also ask

What is meant by servlet container?

A servlet container is an implementation of the Jakarta Servlet specification, used primarily for hosting servlets. A web server is a server designed to serve files from the local system, like Apache. A Java enterprise application server is a full-blown implementation of the Jakarta EE specification.

What is difference between servlet and servlet container?

A servlet is a component that generates dynamic content to run inside a servlet container. For HydraExpress, the container is hosted inside the HydraExpress Agent. The servlet container provides the runtime environment for the servlet.

What is the use of servlet container?

The servlet container provides the servlet with easy access to properties of the HTTP request, such as its headers and parameters. When a servlet is called, such as when it is specified by URL, the Web server passes the HTTP request to the servlet container. The container, in turn, passes the request to the servlet.

What is servlet container in spring boot?

A Servlet Container or Web Container (like Tomcat) is an implementation of various Java EE specifications like Java Servlet, JSP, etc. Put in a simple way, it is an environment where Java web applications can live. A web server + Java support.


2 Answers

The "dynamic" classpath will list WEB-INF/classes and each JAR file under WEB-INF/lib as a separate entry. Other folders under WEB-INF are not included.

In your example, bar.properties will not be on the classpath. Move it to WEB-INF/classes, or put it inside a JAR file under WEB-INF/lib.

What's in the rest of the classpath depends on your servlet container. It is implementation-specific, but most containers have two other places to put classes. One is a directory that is visible to the container, but not the applications, and the other is visible to the container and all of the applications. Since the second classloader is visible to all of the applications, static members of those classes can be used to share information between applications.

like image 185
erickson Avatar answered Oct 10 '22 03:10

erickson


In your example bar.properties would need to be under the classes directory to be in the classpath.

like image 24
rich Avatar answered Oct 10 '22 03:10

rich