Tomcat 7 mystery
Jul. 17th, 2015 09:50 pmAccording to the Tomcat Class Loader How-To page, Tomcat has 4 class loaders.
The Bootstrap class loader loads Java stuff.
The System class loader, when using the Tomcat startup scripts, loads a few jars from the Tomcat bin folders.
The Common class loader loads jars from the Tomcat lib folders.
The WebappX class loader loads jars from the application's WEB-INF/classes and lib folders.
My application's open-source jars are all maintained in a few special folders. For testing the application, I want Tomcat to load the jars from those folders, to avoid having to copy all the jars into the WEB-INF/lib folder. (I don't want to build and deploy a WAR file just for testing).
So, I'm using a "setenv.bat" file in the CATALINA_BASE/bin folder, with a SET CLASSPATH statement to load the jars from the open-source folders.
I start Tomcat with the startup.bat file (on Windows). It works. But only when I also include Tomcat\bin\tomcat-juli.jar and Tomcat\lib\servlet-api.jar in the SET CLASSPATH statement. Otherwise Tomcat gets startup errors.
I understand why tomcat-juli.jar needs to be included even though the System class loader is supposed to load it. My open-source jars include a different version of the juli jar, which is not the one Tomcat needs. When the open-source juli jar is in the WEB-INF\lib folder, the Tomcat\bin version takes precedence. However, when it is in the SET CLASSPATH statement in setenv.bat, it gets loaded first unless you list the other jar first.
The mystery (to me), is why do I need to include servlet-api.jar in the SET CLASSPATH statement? My open source folders (as far as I can tell) don't have any other version of that jar. When I don't include the jar in the statement, I get a ClassNotFound error on javax.servlet.ServletContainerInitializer.
According to the Tomcat documentation, servlet-api.jar is supposed to be loaded by the Common class loader. So why doesn't that happen?
Is the Common class loader not used, when starting Tomcat via the startup scripts?
Process Explorer seems to show that the Tomcat\lib\ jars are all loaded - they are listed in the Java process' "Files" section.
The Bootstrap class loader loads Java stuff.
The System class loader, when using the Tomcat startup scripts, loads a few jars from the Tomcat bin folders.
The Common class loader loads jars from the Tomcat lib folders.
The WebappX class loader loads jars from the application's WEB-INF/classes and lib folders.
My application's open-source jars are all maintained in a few special folders. For testing the application, I want Tomcat to load the jars from those folders, to avoid having to copy all the jars into the WEB-INF/lib folder. (I don't want to build and deploy a WAR file just for testing).
So, I'm using a "setenv.bat" file in the CATALINA_BASE/bin folder, with a SET CLASSPATH statement to load the jars from the open-source folders.
I start Tomcat with the startup.bat file (on Windows). It works. But only when I also include Tomcat\bin\tomcat-juli.jar and Tomcat\lib\servlet-api.jar in the SET CLASSPATH statement. Otherwise Tomcat gets startup errors.
I understand why tomcat-juli.jar needs to be included even though the System class loader is supposed to load it. My open-source jars include a different version of the juli jar, which is not the one Tomcat needs. When the open-source juli jar is in the WEB-INF\lib folder, the Tomcat\bin version takes precedence. However, when it is in the SET CLASSPATH statement in setenv.bat, it gets loaded first unless you list the other jar first.
The mystery (to me), is why do I need to include servlet-api.jar in the SET CLASSPATH statement? My open source folders (as far as I can tell) don't have any other version of that jar. When I don't include the jar in the statement, I get a ClassNotFound error on javax.servlet.ServletContainerInitializer.
According to the Tomcat documentation, servlet-api.jar is supposed to be loaded by the Common class loader. So why doesn't that happen?
Is the Common class loader not used, when starting Tomcat via the startup scripts?
Process Explorer seems to show that the Tomcat\lib\ jars are all loaded - they are listed in the Java process' "Files" section.