Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Thomas Kellerer" Subject: Re: Dynamic classpath Message-ID: <68d9soF2r6qjbU1@mid.individual.net> X-Comment-To: comp.lang.java.gui,comp.l Newsgroups: comp.lang.java.gui In-Reply-To: References: Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 34 Date: Wed, 27 Apr 2011 15:45:04 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303919104 96.60.20.240 (Wed, 27 Apr 2011 10:45:04 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:45:04 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:3471 To: comp.lang.java.gui,comp.l wizard of oz, 07.05.2008 10:41: > I have a need to have a classpath that is determined by the set of jars > a user places into a directory. > > By way of example, placing jar's into certain directories in a tomcat > web server will cause tomcat to include them into the web applications > class path. An example of this might be a charting package used by the > web app to generate charts. > > In my specific example, I am building a query tool and I want to be able > to tell users to simply drop the JDBC drivers into a directory and my > app will "pick them up". Thus there would be no need to edit the classpath. > > My target environment is Java 6.0 > You will need to use a URLClassLoader to load the driver(s) The only problem is then doing the connection as the DriverManager will refuse to use a driver that was loaded by a different classloader. You have two options to resolve this: 1) use Connection.connect(String, Properties) directly (bypassing DriverManager) 2) create a wrapper class that pretends to be a driver but delegates everything to the real instance (loaded by your own classloader). I am using option 1) without any problems. Thomas --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24