Results 1 to 4 of 4

Thread: Loading a JAR dynamically

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    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

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    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?!

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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
  •  



Click Here to Expand Forum to Full Width