|
-
Aug 26th, 2003, 05:23 AM
#1
Thread Starter
Addicted Member
Loading a JAR dynamically
Hello
I have a Java App that needs to use JDBC Driver from various vendors, the thing is i don't know which at run time, so need someway of adding the JAR to my Apps Class Path so i can then load it as i would normally. Except i need this done while the application is running.
Now is this possible? and if so how'd i go about doing it as i've had no luck so far
So far, I've tried to extend URLClassLoader to handle the new jar file, using this (with loader.loadClass(name)), and also using a seperate thread and the contextclassloader of that. However, none of the things I've tried seem to work correctly. I would have thought that one of the things in the class was meant to add it to the DriverManager as soon as it was added using a loader.
Do I need to do something incredibly weird? I'm totally baffled.
Andy
-
Aug 28th, 2003, 05:26 AM
#2
Why not place the driver jars in the lib/ext directory of the JRE? It should be found there.
Then there is a static method of Class called forName or something:
Class driver = Class.forName("com.mysql.Driver");
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Aug 28th, 2003, 05:32 AM
#3
Thread Starter
Addicted Member
hrm
I can't really rely on the fact that third parties will have the JAR's in that folder,
i was kind of hoping i could use them from anywhere on a persons system?!
-
Aug 28th, 2003, 08:40 AM
#4
They only need to be in the class path. This is easy to do. lib/ext is useful simply because the class path always points there.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|