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?
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.
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.
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.
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.
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.
In your example bar.properties would need to be under the classes directory to be in the classpath.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With