IDependOn-Set: 1
IDependOn-Set: 119
IDependOn-Set: 161
IDependOn-Set: 163
IDependOn-Set: 165
IDependOn-Set: 2
LastModifiedSecs: 926781512
Parent: 119
SequenceNumber: 7
Title: Dynamically loading classes from servlets
Part: 0
Author-Set: pier@apache.org
LastModifiedSecs: 926781512
Type: html
Lines: 27
Many users complained about the fact that after placing a certaing set of files in a repository, these files were not accessed via <code>Class.forName()</code> or equivalent methods. Others also noticed that, moving the same entry from the "<code><i>repository=</i></code>" property in file <i>zone.properties</i> to the "<code><i>wrapper.classpath=</i></code>" in <i>jserv.properties</i> file, resulted in successfully restoring this capability.<br>
<br>
In other words:<br>
<pre>
   <i><font color="#ff0000">[jserv.properties]</font></i>
   wrapper.classpath=/usr/java/lib/jsdk20.jar

   <i><font color="#ff0000">[zone.properties]</font></i>
   repository=/usr/java/servlets,<font color="#0000ff">/usr/java/lib/foo.jar</font>
</pre>
<code>Class.forName("org.foo.Bar")</code> doesn't work (where class "<code>org.foo.Bar</code>" is contained in "<i>/usr/java/lib/foo.jar</i>")
while <br>
<pre>
   <i><font color="#ff0000">[jserv.properties]</font></i>
   wrapper.classpath=/usr/java/lib/jsdk20.jar:<font    color="#0000ff">/usr/java/lib/foo.jar</font>

   <i><font color="#ff0000">[zone.properties]</font></i>
   repository=/usr/java/servlets
</pre>
<code>Class.forName("org.foo.Bar")</code> works.<br>
<br>
This happens because repositories are NOT merged with the JVM class path, and, so, unaccessible from the system ClassLoader.<br>
<br>
But why that? Because, to be able to give to JServ the ability of autoreloading servlet classes when these were changed, we had to create a different ClassLoader, and to use a different ClassLoader for each servlet zone.<br>
<br>
This also gives other benefits, expecially about security, in fact a certain zone cannot access classes and servlets specified in a different zone, and so a servlet in zone "<code>Foo</code>" cannot access to the servlet "<code>MyServlet</code>" specified in zone "<code>Bar</code>" when these two zones have different "<code>repository=<code>" entries in the two <i>zone.properties</i> files.<Br>
<br>
EndPart: 0
