Note that there are some explanatory texts on larger screens.

plurals
  1. POTomcat class loading order when serving modules without publishing
    primarykey
    data
    text
    <p>I am using tomcat with eclipse.</p> <p>According to tomcat's documentation:<br /><br /> <strong>from the perspective of a web application, class or resource loading looks in the following repositories, in this order:</strong><br/></p> <ul> <li>Bootstrap classes of your JVM System class loader classes (described above)</li> <li>/WEB-INF/classes of your web application </li> <li>/WEB-INF/lib/*.jar of your web application </li> <li>Common class loader classes (described above)</li> </ul> <p>So when loading a classes, tomcat will look up <strong>WEB-INF/classes</strong> before <strong>WEB-INF/lib</strong>. And we can overwrite some class in jar files in WEB-INF/lib, tomcat will pick up the overwritten one.</p> <p>But now if I changed the tomcat server options by checking "Serve modules with out publishing" , then overwritten classes will not be loaded any more.</p> <p>Is there any solution to make that works again, but I still want tomcat to serve modules without publishing.</p> <hr> <p>Edits:<br /> I have found something may be useful, in this folder <strong>f:\eclipse_projects\.metadata.plugins\org.eclipse.wst.server.core\tmp0\conf</strong> there is a server.xml it contains such content:</p> <pre><code>&lt;Resources className="org.eclipse.jst.server.tomcat.loader.WtpDirContext" extraResourcePaths="" virtualClasspath="F:\eclipse_projects\ALS7C3\bin"/&gt; &lt;Loader className="org.eclipse.jst.server.tomcat.loader.WtpWebappLoader" useSystemClassLoaderAsParent="false" virtualClasspath="F:\eclipse_projects\ALS7C3\bin"/&gt; </code></pre> <p>It seems that when running tomcat with option "Serve modules without publishing" checked, eclipse will use it's own loader.This loader is contained in a jar file which will be copied to <strong>f:\eclipse_projects\.metadata.plugins\org.eclipse.wst.server.core\tmp0\lib** when you start tomcat in eclipse. Here is part of source code of **org.eclipse.jst.server.tomcat.loader.WtpDirContext</strong>:</p> <pre><code>public Object lookup(String name) throws NamingException { if (name.startsWith("/WEB-INF/") &amp;&amp; name.endsWith(".tld")) { String tldName = name.substring(name.lastIndexOf("/") + 1); if (virtualMappings != null &amp;&amp; virtualMappings.containsKey(tldName)) { return new FileResource(virtualMappings.get(tldName)); } } else if (tagfileMappings != null &amp;&amp; name.startsWith("/META-INF/tags") &amp;&amp; (name.endsWith(".tag") || name.endsWith(".tagx"))) { // already loaded tag file return new FileResource(tagfileMappings.get(name)); } Object retSuper; NamingException superEx; try { retSuper = super.lookup(name); return retSuper; } catch (NamingException ex) { retSuper = null; superEx = ex; } if (mappedResourcePaths != null) { // Perform lookup using the extra resource paths for (Map.Entry&lt;String, List&lt;String&gt;&gt; mapping : mappedResourcePaths.entrySet()) { String path = mapping.getKey(); List&lt;String&gt; dirList = mapping.getValue(); if (name.equals(path)) { for (String resourcesDir : dirList) { File f = new File(resourcesDir); if (f.exists() &amp;&amp; f.canRead()) { if (f.isFile()) { return new FileResource(f); } else { // TODO Handle directory } } } } path += "/"; if (name.startsWith(path)) { String res = name.substring(path.length()); for (String resourcesDir : dirList) { File f = new File (resourcesDir + "/" + res); if (f.exists() &amp;&amp; f.canRead()) { if (f.isFile()) { return new FileResource(f); } else { // TODO Handle directory } } } } } } throw superEx; } </code></pre> <p>it seems that if it will first handle jsp tag library then call <strong>super.lookup</strong>, if can't find in <strong>super.lookup</strong>, it will try to load resource in virtualClasspath, "F:\eclipse_projects\ALS7C3\bin" in my example, it's where eclipse output class files when serving modules without publishing.</p> <p>So, I guess, I can get what I want if I can overwrite the <strong>lookup</strong> method of <strong>org.eclipse.jst.server.tomcat.loader.WtpDirContext</strong>, however this jar file is contained in <strong>org.eclipse.jst.server.tomcat.core.jar</strong>, both of them are signed.</p> <p>I don't know how to overwrite such a jar file.</p> <p>Any one can help ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload