Java load appropriate .jar file at runtime
Posted on 2011-04-29
I am writing an application that uses a third-party .jar file, let's call it x.jar.
On my machine, I can add x.jar to my Netbeans project so I have the classes available while developing and testing (for code completion, parameter checking, etc.).
At run time, when installed on a client's machine, the client's x.jar file may be different than the one I have, so I don't want to send out my x.jar file, but have my program load their x.jar file (I have a routine that can determine the full path to the client's x.jar file at runtime).
I'm not sure how to go about doing this. Do I do a custom classloader? Do I have to set the classpath at runtime?
I'm looking for a solution that
1. allows me to continue to develop in Netbeans (and have the classes show up in the editor) 2. does the runtime loading.
3. whille developing/testing, the program can also load x.jar the same way it would at the client's runtime]
4. Note: when I add x.jar as a dependency in Netbeans, when I do a "build", it copies the x.jar file to the distribution directory, which I don't need.