2014-06-14 17:30 GMT+04:00 Vimil Saju <vimils...@yahoo.com.invalid>:
> 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.
>

1. VirtualWebappLoader is deprecated and removed from Tomcat 8. In
Tomcat 8 you'll configure your resources by mapping those directories
into WEB-INF/classes.

As it is all the same directory (WEB-INF/classes), I see no sense in
filtering by directory name.

JarScanner operates on URLs, not on file system paths.

2. I think that I'd like to see filtering by Java package name. I
think it makes sense to implement that.

3. You may configure your own JarScanner or JarScanFilter (in Tomcat
8) implementation in your META-INF/context.xml file.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to