Hi,

I am using tomcat 7.0.52 and jdk 1.7.0_45. We have a web application which has 
its classpath configured in its own context xml file using virtualClasspath 
attribute of Loader tag. The webapp uses version 3.0 of web.xml,  The classpath 
contains multiple class folders in addition to jar file references. i.e 
virtualClasspath is set to something as follows

virtualClasspath="C:\Projects\ProjectA\classes;C:\Projects\ProjectB\classes;C:\Projects\ProjectC\classes;C:\Projects\Libraries\jarfile1.jar;C:\Projects\Libraries\jarfile2.jar"
 

C:\Projects\ProjectA\classes has classes with Servlet 3.0 annotations and I 
want tomcat to look for annotated classes in this class folder. To do this I 
have set the attribute scanAllDirectories=true under the JarScanner tag as 
follows


<JarScanner scanAllDirectories="true"/>


Since I don't want tomcat to scan other jar files and class folders of ProjectB 
and ProjectC, I have configured 
the property tomcat.util.scan.DefaultJarScanner.jarsToSkip in 
catalina.properties to something as follows

tomcat.util.scan.DefaultJarScanner.jarsToSkip=jarfile1.jar,jarfile2.jar,**/ProjectB/classes,**/ProjectC/classes


I was able to make tomcat skip scanning of jar files using the above 
configuration but it still scans class folders of both ProjectB and ProjectC. 

So I looked at the source code of StandardJarScanner and found that it uses the 
name of the last directory in the folder path as the jar name. i.e the jarName 
computed for both ProjectB/classes and ProjectC/classes is 'classes'. Thus 
there is no way for it to distinguish ProjectB/classes and ProjectC/classes 
from ProjectA/classes.

I think StandardJarScanner should use the full folder path as the jar name 
instead of just the last directory in the folder path.


This is the code I was looking at in StandardJarScanner.java

/*
 * Extract the JAR name, if present, from a URL
 */
private String More ...getJarName(URL url) {

    String name = null;

    String path = url.getPath();
    int end = path.indexOf(Constants.JAR_EXT);
    if (end != -1) {
        int start = path.lastIndexOf('/', end);
        name = path.substring(start + 1, end + 4);
    } else if (isScanAllDirectories()){
        int start = path.lastIndexOf('/');
        name = path.substring(start + 1);
    }

    return name;
}


 I think  instead of computing the last name of the directory path for class 
folders it should set the jarname to the full folder path

private String getJarName(URL url) { String name = null; String path = 
url.getPath(); int end = path.indexOf(".jar"); if (end != -1) { int start = 
path.lastIndexOf('/', end); name = path.substring(start + 1, end + 4); } else 
if (isScanAllDirectories()) { name = path; } return name; }

  I would like to know if there are any issues with my suggestion. I would also 
like to know if there is any workaround for my problem.

Thanks
Vimil

Reply via email to