Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #3470 > unrolled thread
| Started by | "wizard of oz" <wizard.of.oz@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:45 +0000 |
| Last post | 2011-04-27 15:45 +0000 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.lang.java.gui
Dynamic classpath "wizard of oz" <wizard.of.oz@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Dynamic classpath "Thomas Kellerer" <thomas.kellerer@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Dynamic classpath "wizard of oz" <wizard.of.oz@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Dynamic classpath "Thomas Kellerer" <thomas.kellerer@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Dynamic classpath "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Dynamic classpath "Ian Shef" <ian.shef@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
Re: Dynamic classpath "John B. Matthews" <john.b..matthews@THRWHITE.remove-dii-this> - 2011-04-27 15:45 +0000
| From | "wizard of oz" <wizard.of.oz@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Subject | Dynamic classpath |
| Message-ID | <XWdUj.8408$ko5.5712@news-server.bigpond.net.au> |
To: comp.lang.java.gui,comp.l 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 TIA --- * 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
[toc] | [next] | [standalone]
| From | "Thomas Kellerer" <thomas.kellerer@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <68d9soF2r6qjbU1@mid.individual.net> |
| In reply to | #3470 |
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
[toc] | [prev] | [next] | [standalone]
| From | "wizard of oz" <wizard.of.oz@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <UwgUj.8452$ko5.199@news-server.bigpond.net.au> |
| In reply to | #3471 |
To: comp.lang.java.gui,comp.l Can you post an example of Connection.connect (String, properties)? My java doc says java.sql.Connection is an interface and doesn't mention a connect method. TIA "Thomas Kellerer" <YQDHXVLMUBXG@spammotel.com> wrote in message news:68d9soF2r6qjbU1@mid.individual.net... > 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
[toc] | [prev] | [next] | [standalone]
| From | "Thomas Kellerer" <thomas.kellerer@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <68dkudF2sv349U1@mid.individual.net> |
| In reply to | #3472 |
To: comp.lang.java.gui,comp.l
Sorry, I meant Driver.connect()
Once you have loaded the driver class using a URLClassLoader, you can create a new instance and cast that to a Driver and then ask the driver to connect.
Something like this:
URLClassLoader l = new URLClassLoader(...);
Class drvClass = l.loadClass("org.postgresql.Driver");
java.sql.Driver drv = (java.sql.Driver)drvClass.newInstance();
Properties props = new Properties();
props.put("user", "postgres");
props.put("password", "password");
java.sql.Connection conn = drv.connect("jdbc:postgresql:localhost/mydb", props);
Regards
Thomas
wizard of oz, 07.05.2008 13:38:
> Can you post an example of Connection.connect (String, properties)?
>
> My java doc says java.sql.Connection is an interface and doesn't mention a
> connect method.
>
> TIA
>
> "Thomas Kellerer" <YQDHXVLMUBXG@spammotel.com> wrote in message
> news:68d9soF2r6qjbU1@mid.individual.net...
>> 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
[toc] | [prev] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <itc324p2e2j1jheirhkaniadfmlme9cfi4@4ax.com> |
| In reply to | #3470 |
To: comp.lang.java.gui,comp.l You can change the classpath on the fly by firing up a new ClassLoader. See http://mindprod.com/jgloss/classcloader.html -- Roedy Green Canadian Mind Products The Java Glossary http://mindprod.com --- * 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
[toc] | [prev] | [next] | [standalone]
| From | "Ian Shef" <ian.shef@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <Xns9A9F7898AECB8vaj4088ianshef@138.126.254.210> |
| In reply to | #3476 |
To: comp.lang.java.gui,comp.l Roedy Green <see_website@mindprod.com.invalid> wrote in news:itc324p2e2j1jheirhkaniadfmlme9cfi4@4ax.com: > You can change the classpath on the fly by firing up a new > ClassLoader. > See http://mindprod.com/jgloss/classcloader.html In case it wan't obvious, I believe that Roedy meant http://mindprod.com/jgloss/classloader.html --- * 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
[toc] | [prev] | [next] | [standalone]
| From | "John B. Matthews" <john.b..matthews@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:45 +0000 |
| Message-ID | <nospam-C6E7A1.20012715052008@news-server.woh.rr.com> |
| In reply to | #3503 |
To: comp.lang.java.gui,comp.l In article <Xns9A9F7898AECB8vaj4088ianshef@138.126.254.210>, Ian Shef <invalid@avoiding.spam> wrote: > Roedy Green <see_website@mindprod.com.invalid> wrote in > news:itc324p2e2j1jheirhkaniadfmlme9cfi4@4ax.com: > > > You can change the classpath on the fly by firing up a new > > ClassLoader. > > See http://mindprod.com/jgloss/classcloader.html > > In case it wan't obvious, I believe that Roedy meant > > http://mindprod.com/jgloss/classloader.html Perhaps. The class java.tenebrous.ClassCLoader, now deprecated, is the abstract superclass of all cassette tape loaders. It was one of the first to implement the ScrollKeyboard interface, although it required Ackerman(m,n) time to complete:-) John -- John B. Matthews trashgod at gmail dot com home dot woh dot rr dot com slash jbmatthews --- * 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web