From: "Paul Brinkley" <[EMAIL PROTECTED]> Sent: Tuesday, July 30, 2002 2:14 PM Subject: Add arbitrary path to classpath?
> (Newbie alert: I've been playing with Tomcat for a couple weeks, and once > made a servlet or two a couple of years ago. Please be gentle.) > > Is it possible to give a servlet access to custom class files, if those > custom classes don't want to live under WEB-INF, CATALINA_HOME, etc.? Well, let's start with the "Doc, it hurts when I..." lines. Why don't these classes want to live in WEB-INF or CATALINA_HOME? Did the COPY command on your system stop working? > So far as I can tell after reading > > tomcat-docs/class-loader-howto.html > > four times, as well as rampant websearching, there's no way to do this in a > reasonably portable way. Portable how? To different Servlet containers? Different OSes? > I would also prefer not to have to change the Tomcat startup scripts. This > wouldn't be portable to another web server, and it would also add > complexity to the installation instructions that I'd rather avoid. Plus, > it would expose our code to other servlets. If I can control visibility > of this custom code to other servlets possibly running on a given engine, > great. > > Tomcat 4.0.4 (but I'd prefer a solution that's portable to other engines if > possible) > OS: Win2000, but again, the more portable, the better > Servlet is unpacked (not in a war file) The solution is to follow the spec, drop your classes into WEB-INF/classes and WEB-INF/lib and call it a day. These classes aren't shared with any other servlets, so they're safe. This is completely portable as it's the "only" way that's guaranteed by the Servlet specification, anything else is platform dependant and therefore, by definition, not portable. Done properly, there is no configuration for deployment. I think Tomcat made the correct decision to completely ignore CLASSPATH for the deployed applications. This give the container a LOT of flexibility, and I've yet to see a compelling reason to NOT do it. Jar files are not directories. Java Packages are not directories. This is an Illusion that people have because of their current implementation. Your application DOES NOT CARE where or how the JVM locates classes, so why should you? When you care about how your application locates classes, is when you start to write your own ClassLoaders. 99.99% of the time, this isn't what you want to do. So, do that smart thing, stick a couple of MKDIR and XCOPY commands into your build script, move the files to the Right Places within the webapp, and quit wasting time trying to fight this battle. Embrace and love the WAR and webapp. It's your friend. Really! Regards, Will Hartung ([EMAIL PROTECTED]) -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
