RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository
> From: Akoulov, Alexandre [IT] [mailto:[EMAIL PROTECTED] > Subject: RE: Problem with the classloader in > jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > > Please let me know what you think It doesn't really matter what I think - I'm not a Tomcat developer. If you believe the area needs changing, you'll need to submit a Bugzilla report and convince Remy. Best if you report it against the 5.5 leg, since that's the one under active development. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository
>Apparently, individual jars should be added as URLs rather than >normal file system paths. I suppose that means using >file:.jar, but I haven't tried it. I guess that would work because Bootstrap.java has the following piece of code in its createClassLoader(String, ClassLoader) - // Check for a JAR URL repository try { urlList.add(new URL(repository)); continue; } catch (MalformedURLException e) { // Ignore } - Chuck, but would not be better if we fix the actual problem in the ClassLoaderFactory#createClassLoader. Then people would not be spending time working out why they cannot load a jar file :) We already have a fix - see below : ---FIX-in ClassLoaderFactory#createClassLoader--- // Add unpacked directories //if (unpacked != null) { //for (int i = 0; i < unpacked.length; i++) { //File file = unpacked[i]; //if (!file.exists() || !file.canRead()) //continue; //if (debug >= 1) //log(" Including directory or JAR " //+ file.getAbsolutePath()); //URL url = new URL("file", null, // file.getCanonicalPath() + File.separator); //list.add(url.toString()); //} //} // if (unpacked != null) { for (int i = 0; i < unpacked.length; i++) { File file = unpacked[i]; if (!file.exists() || !file.canRead()) continue; if (debug >= 1) log(" Including directory or JAR " + file.getAbsolutePath()); // THE FIX !!! StringBuffer filePath = new StringBuffer(file.getCanonicalPath()); if ( file.isDirectory() ) { // Only add a file separator if a file represents a directory filePath.append(File.separator); } URL url = new URL("file", null, filePath.toString()); list.add(url.toString()); } } Please let me know what you think -Original Message- From: Caldarale, Charles R [mailto:[EMAIL PROTECTED] Sent: Friday, 22 April 2005 4:09 PM To: Tomcat Users List Subject: RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > From: Akoulov, Alexandre [IT] [mailto:[EMAIL PROTECTED] > Subject: RE: Problem with the classloader in > jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > > However, if you add a reference to the actual jar file (eg, > shared.loader=${catalina.home}/shared/lib/velocity-dep-1.3.1.j > ar) you will not be able to use any classes from it but > rather will get ClassNotFoundException. This is the actual problem! This appears to be the same situation described in Bugzilla entry 23344 (see http://issues.apache.org/bugzilla/show_bug.cgi?id=23344 for details) which was marked as fixed in September 2003 in level 5.0.12. Apparently, individual jars should be added as URLs rather than normal file system paths. I suppose that means using file:.jar, but I haven't tried it. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository
> From: Akoulov, Alexandre [IT] [mailto:[EMAIL PROTECTED] > Subject: RE: Problem with the classloader in > jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > > However, if you add a reference to the actual jar file (eg, > shared.loader=${catalina.home}/shared/lib/velocity-dep-1.3.1.j > ar) you will not be able to use any classes from it but > rather will get ClassNotFoundException. This is the actual problem! This appears to be the same situation described in Bugzilla entry 23344 (see http://issues.apache.org/bugzilla/show_bug.cgi?id=23344 for details) which was marked as fixed in September 2003 in level 5.0.12. Apparently, individual jars should be added as URLs rather than normal file system paths. I suppose that means using file:.jar, but I haven't tried it. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository
>The standard catalina.properties already has several jars and several >directories specified for the various class loaders, standard catalina.properties has refs to "*.jar" (eg, ${catalina.home}/common/endorsed/*.jar) not to the actual jar file. Bootstrap.java then checks whether there is "*.jar" at the end of the path, strips it from the path and then adds to the packed list. If the path ends in anything other than "*.jar" it gets added to unpacked list (that is where the jar file ends up) -- if (repository.endsWith("*.jar")) { packed = true; repository = repository.substring (0, repository.length() - "*.jar".length()); } if (packed) { packedList.add(new File(repository)); } else { unpackedList.add(new File(repository)); } -- However, if you add a reference to the actual jar file (eg, shared.loader=${catalina.home}/shared/lib/velocity-dep-1.3.1.jar) you will not be able to use any classes from it but rather will get ClassNotFoundException. This is the actual problem! >Read the javadoc for the class in question. (The full URL is >http://jakarta.apache.org/tomcat/tomcat-5.0-doc/catalina/docs/api/org/ap >ache/catalina/startup/ClassLoaderFactory.html#createClassLoader(java.io. >File[],%20java.io.File[],%20java.net.URL[],%20java.lang.ClassLoader).) Well, the java doc says that "packed - Array of pathnames to DIRECTORIES CONTAINING JAR files that should be added to the repositories of the class loader, or null for no directories of JAR files to be considered" (not the actual jar files). At the same time java doc indicates that "unpacked - Array of pathnames to unpacked directories that should be added to the repositories of the class loader, or null for no unpacked directories to be considered". I guess here it means that a jar file is already considered to be unpacked directory. This conclusion can be drawn from the Bootstrap.java code extract (see above) and more importantly from the actual ClassLoaderFactory#createClassLoader method's source: if (unpacked != null) { for (int i = 0; i < unpacked.length; i++) { File file = unpacked[i]; if (!file.exists() || !file.canRead()) continue; if (debug >= 1) log(" Including directory or JAR " // LOOK HERE - expects directory or a JAR file + file.getAbsolutePath()); .. .. if (packed != null) { for (int i = 0; i < packed.length; i++) { File directory = packed[i]; if (!directory.isDirectory() || !directory.exists() || !directory.canRead()) // LOOK HERE - only expects to find directories in here, not the files!!! continue; -Original Message- From: Caldarale, Charles R [mailto:[EMAIL PROTECTED] Sent: Friday, 22 April 2005 3:13 PM To: Tomcat Users List Subject: RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > From: Akoulov, Alexandre [IT] [mailto:[EMAIL PROTECTED] > Sent: 2005 April 21, Thursday 19:48 > Subject: RE: Problem with the classloader in > jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > > I still think it is a bug!!! Read the javadoc for the class in question. (The full URL is http://jakarta.apache.org/tomcat/tomcat-5.0-doc/catalina/docs/api/org/ap ache/catalina/startup/ClassLoaderFactory.html#createClassLoader(java.io. File[],%20java.io.File[],%20java.net.URL[],%20java.lang.ClassLoader).) The first parameter is for directories, the second for jars, which is why they're named "unpacked" and "packed", respectively. > Please try the following: add a jar file (eg, foo/bar.jar) as > a class repository in the catalina.properties The standard catalina.properties already has several jars and several directories specified for the various class loaders, and they all seem to work fine in the levels I'm using (5.0.28 and 5.5.7) - otherwise Tomcat wouldn't even be able to start up. What specifically did you change in catalina.properties that led you to believe there's a problem? - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachme
RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository
> From: Akoulov, Alexandre [IT] [mailto:[EMAIL PROTECTED] > Sent: 2005 April 21, Thursday 19:48 > Subject: RE: Problem with the classloader in > jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > > I still think it is a bug!!! Read the javadoc for the class in question. (The full URL is http://jakarta.apache.org/tomcat/tomcat-5.0-doc/catalina/docs/api/org/ap ache/catalina/startup/ClassLoaderFactory.html#createClassLoader(java.io. File[],%20java.io.File[],%20java.net.URL[],%20java.lang.ClassLoader).) The first parameter is for directories, the second for jars, which is why they're named "unpacked" and "packed", respectively. > Please try the following: add a jar file (eg, foo/bar.jar) as > a class repository in the catalina.properties The standard catalina.properties already has several jars and several directories specified for the various class loaders, and they all seem to work fine in the levels I'm using (5.0.28 and 5.5.7) - otherwise Tomcat wouldn't even be able to start up. What specifically did you change in catalina.properties that led you to believe there's a problem? - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository
Thanks Chuck for your reply. I still think it is a bug!!! Please try the following: add a jar file (eg, foo/bar.jar) as a class repository in the catalina.properties and then use one of the classes from this jar file in one the servlets - will get a ClassNotFoundException. I've attached ClassLoaderFactoryTest.java and ClassLoaderFactoryWithTheFix.java. Please try to run the test - one of the tests will fail, refer to the place where it fails and read the comments. Kind regards, Alex. -Original Message- From: Caldarale, Charles R [mailto:[EMAIL PROTECTED] Sent: Thursday, 21 April 2005 9:27 PM To: Tomcat Users List Subject: RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > From: Akoulov, Alexandre [IT] [mailto:[EMAIL PROTECTED] > Subject: Problem with the classloader in > jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > > ClassLoaderFactory#createClassLoader(File unpacked[], File > packed[], URL urls[], ClassLoader parent) is the actual > method that creates class loaders. The very first argument to > this method contains jar files or directories ( that is where > the name "unpacked" comes from ). >From what I can tell, it's the _second_ argument that should contain .jar files; the first is for directories only. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -Original Message- From: Akoulov, Alexandre [IT] Sent: Thursday, 21 April 2005 6:29 PM To: tomcat-user@jakarta.apache.org Subject: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository Hi all, I'd greatly appreciate your thoughts on the following issue (and the proposed solution ): When adding a jar file (eg, "foo/bar.jar") to the class loader's repository it treats as a directory and therefore it cannot load any classes from this jar. The following explains why it happens. org.apache.catalina.startup.ClassLoaderFactory is responsible for creating class loader instances. Each instance is of org.apache.catalina.loader.StandardClassLoader type, which in its turn extends java.net.URLClassLoader: - public class StandardClassLoader extends URLClassLoader - ClassLoaderFactory#createClassLoader(File unpacked[], File packed[], URL urls[], ClassLoader parent) is the actual method that creates class loaders. The very first argument to this method contains jar files or directories ( that is where the name "unpacked" comes from ). ClassLoaderFactory#createClassLoader method adds File.separator to the end of the jar file path ( file.getCanonicalPath() + File.separator ) when constructing a URL instance to represent a jar file and then adds a string representation of a newly created URL to its list of repositories ( list.add(url.toString()) ) : - if (unpacked != null) { for (int i = 0; i < unpacked.length; i++) { File file = unpacked[i]; if (!file.exists() || !file.canRead()) continue; if (debug >= 1) log(" Including directory or JAR " + file.getAbsolutePath()); URL url = new URL("file", null, file.getCanonicalPath() + File.separator); list.add(url.toString()); } } - For instance, if "unpacked" argument contains '/home/aa/lib/velocity.jar' then a URL object is 'file:/home/aa/lib/velocity.jar/' - a forward slash / (which is a Unix file separator) has been added to the url. After ClassLoaderFactory#createClassLoader adds all repositories to its repository list it converts this list to array and constructs StandardClassLoader with it: - String array[] = (String[]) list.toArray(new String[list.size()]); Sta
RE: Problem with the classloader in jakarta-tomcat-5.0.28 - cannot add a jar file to class repository
> From: Akoulov, Alexandre [IT] [mailto:[EMAIL PROTECTED] > Subject: Problem with the classloader in > jakarta-tomcat-5.0.28 - cannot add a jar file to class repository > > ClassLoaderFactory#createClassLoader(File unpacked[], File > packed[], URL urls[], ClassLoader parent) is the actual > method that creates class loaders. The very first argument to > this method contains jar files or directories ( that is where > the name "unpacked" comes from ). >From what I can tell, it's the _second_ argument that should contain .jar files; the first is for directories only. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]