: Hello, I want to load a class from a JAR file. It is saved under
/mnt/datadisk/java/share, but altough I add it to library path the program fails loading class. here is code I use:
System.setProperty("java.library.path",
System.getProperty("java.library.path")+":"+"/mnt/datadisk/java/share");
Changing this String has no effect (as you have found). Same goes for all the properties stored here (user directory etc).
If you want to load classes dynamically, try
java.net.URLClassLoader. Either construct a
file:// type url or use the
File.toUrl() method. Use the
loadClass method to get the
java.lang.Class and then use its
newInstance method to instantiate it. You can use
java.lang.reflect.Constructors if they take arguments.
This method of instantiation is only suitable if the type is in the main classpath (otherwise you'll still get class not found exceptions). But it'll work for JDBC drivers + the like.
---------------------------------
(Its just my sig)
HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html