Article View: borland.public.jbuilder.java.language
Article #164Re: changing class path at run time
From: Paul Furbacher [TeamB]
Date: Tue, 28 Mar 2006 21:50
Date: Tue, 28 Mar 2006 21:50
62 lines
2944 bytes
2944 bytes
George wrote:
> I guess I spoke too soon.
>
> I'm having trouble going the URLClassLoader route. The code below
> succeeds in loading the Oracle jdbc driver...however the call to
> DriverManager.getConnection() returns saying "No suitable
> driver"...
>
> George
>
> try {
> File f = new File(System.getProperty("user.dir") + "\\ojdbc14.jar");
> URL url = new URL("file:///"+ f.getAbsolutePath());
> URL [] urlList = new URL[1];
> urlList[0] = url;
> URLClassLoader cld = new URLClassLoader(urlList);
> Class cl = cld.loadClass("oracle.jdbc.OracleDriver");
> Connection connection =
DriverManager.getConnection(
"jdbc:oracle:thin:@STPDB1P:1521:STP20P1", "fo", "fo");
> } catch (Exception ex) {
> ex.printStackTrace();
> }
If I look at how the Cayenne folks do it (Andrei Adamchik,
specifically) in
org.objectstyle.cayenne.modeler.FileClassLoadingService
I notice that the new classloader is instantiated with a
parent classloader.
That's different from how you have done it. Maybe that's
the difference; try
URLClassLoader cld =
new URLClassLoader(
new URL [] { url },
this.getClass().getClassLoader() );
Also, have you stepped through the above code in the
debugger and ascertained that "cl" is not null? You
hinted that you have when you wrote "... succeeds in
loading the Oracle jdbc driver...", but I just want to
be sure.
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Technical Details
Message-ID:
<4429afa9$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<442953d2$1@newsgroups.borland.com> <44296071$1@newsgroups.borland.com> <4429630f@newsgroups.borland.com> <4429a3e5@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,93e0a6dd5feccd47 X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 28 Mar 2006 16:50:31 -0500 From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com> Organization: Reverse Alchemy, Inc. User-Agent: Thunderbird 1.5 (Macintosh/20051201) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: changing class path at run time References: <442953d2$1@newsgroups.borland.com> <44296071$1@newsgroups.borland.com> <4429630f@newsgroups.borland.com> <4429a3e5@newsgroups.borland.com> In-Reply-To: <4429a3e5@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.142.194.228 Message-ID: <4429afa9$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1143582633 69.142.194.228 (28 Mar 2006 13:50:33 -0700) Lines: 62 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail