-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Sreyan,
On 4/23/15 9:22 AM, Sreyan Chakravarty wrote: > So what happens when I add something to the build path of a > web-app? The "build path" is an Eclipse concept that has no meaning after the application has been built. > The dependency is not registered? What dependency? Where would it be registered? The only think Java knows about is the current thread's context ClassLoader and what it can see. And the DriverManager always uses the System classloader to find drivers automatically. Have a look at the source code for DriverManager. It should be in src.zip:java/sql/DriverManager.java. The method you're looking for is "loadInitialDrivers" (at least in Oracle's JRE.. it's not a public part of the API). > Also does that mean that whatever dependency I need I will have to > put it in the /lib folder? What other dependency? > I just don't understand why it doesn't work if I add it to the > Build Path from Eclipse like I do for a normal Java Application. Because Tomcat does ClassLoading in a more complicated way than with a standard Java application, where every library is just thrown into the system classpath. Tomcat does this to enforce certain security requirements, to provide insulation against other components, to support embedded usage, and to support plugability of certain features. I'm sorry to say that you simply must call Class.forName to load your driver. If you use either of Tomcat's built-in connection pools (one based upon commons-dbcp, the other called tomcat-pool), you won't have to call Class.forName because the pool will do that for you. You don't have to put the JDBC driver into Tomcat's lib/ directory; you can put it into your web application's WEB-INF/lib directory instead, just like all the other libraries that your web application requires. But be aware that *many* JDBC drivers are poorly-written, and can cause all kinds of memory leaks when the application is undeployed or re-loaded. Hope that helps, - -chris > On Thu, Feb 19, 2015 at 2:19 AM, Christopher Schultz < > ch...@christopherschultz.net> wrote: > > Sreyan, > > (Sorry, I sent way before I was done writing. Full intentional > message follows.) > > On 2/18/15 10:15 AM, sreya...@gmail.com wrote: >>>> What is the SYSTEM PATH that you are referring to ? Is it >>>> the JAVA_HOME or the PATH system variable ? > > Neither of those. It's commonly referred to as the CLASSPATH > environment variable, which should pretty much never be set > because it's horribly confusing. > > Instead, Tomcat uses "java -classpath [the classpath]" to launch > the JVM. The classpath used there includes two JAR files: > >>>> bin/bootstrap.jar bin/tomcat-juli.jar > > So the only thing that javax.sql.DriverManager can scan is the > boot classpath (that includes all the JVM internals) plus the > system classpath (which includes just those two specific JARs > above). > >>>> What is the CLASSPATH just before Tomcat properly starts up? > > The boot class path includes JVM stuff (rt.jar, etc.) > > The system class path includes anything the JVM environment was > instructed to load when launched (either from the CLASSPATH > environment variable, or from the "-classpath" argument on the > command-line). > > Tomcat's bootstrap class creates a new ClassLoader which includes > everything in lib/*.jar and then starts the Tomcat container using > *that* as the effective "class path". > >>>> What is it after it starts up? > > Well, Tomcat can see everything in the boot and system class paths > (ClassLoaders) plus everything in lib/*.jar. > >>>> Correct me if I am wrong that means that whatever >>>> dependencies I have in my project is not added to the SYSTEM >>>> CLASSPATH but is instead loaded by TOMCAT. > > Correct. > >>>> So if a module searches only the SYSTEM CLASSPATH it won’t be >>>> able to find the dependencies. Am I right ? > > Correct. And DriverManager can't search *down* into ClassLoaders > it doesn't know about -- including Tomcat's ClassLoader. So, > DriverManager can't load your JDBC driver using its standard > detection algorithm. > > So, you still need to call Class.forName to register the driver. > > -chris >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> >> > -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: GPGTools - http://gpgtools.org iQIcBAEBCAAGBQJVOkZpAAoJEBzwKT+lPKRYxIoQAI4rf1nfa5RWsMWFHb98dIDi /1KHw9EgjtUI0n+HP5AthmeHYUhXolrUsiFnx+gfmspViKF/wTs0iVUkyZjRTPF0 m1v3DNfy/VvvRpXiEyLUJbvSfzkLo+Axg3tH/licfcZbhKi16ubeGDUWYq9juSBm O8GiYrifkJbYVNYU/FT1wlp68agvgQlYDqygrVz3bhv5rYVlCfX/ja5LUyZPlJeu 556cLNmV0tNAVG+dpK2wfz/uZoa6QrO9CR02GCdSqq+opBiQN2uxwweiY5Zl2REf N3G37ixDEa2hTJLb0H3YBymIZfSB5jxe2AAOV+iVwTMMznl1wClR9matzF/w3NP8 RgJimcAgDOdAILE1I+J9p8Tl6DMPR13vJc9IF0GzUWoApiZ9MS+6Q4PUWFuFVxTY oUTiXeeWY6FkBj4GdCx38tk4r2+6Vh3COnzK0E0wTxpAtJIC6P8zsFtXouS8zjm5 8hQl2aMKrumYE7ZC1RuKQnJ5QGWGMcyb+RbVEoXPOKjYDVl3sxZPjn23gd0zjlyd DgsSKhH8xz44eVcRzBfrYTd59Lod2XxWmlbVJOLbfw6ntergPHc4eUplP7v8uppf cZh4E0JaAOePo/XSU4R0GkIYym54dsci/adkakTaI/l00pai4XNUj0jORFnv2h18 HRDS3U/QXBKHN6aL8liJ =p+Tj -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org