powered by Jive Software

Messenger plugin classpath


I need to load a class dynamically at runtime form a messenger plugin. This works fine if the class is inside the plugin jar but I would like to know if it is possible to load it from outside this jar.

I printed the java.class.path property while inside the plugin but it only points to startup.jar.

Is there any way to load classes outside the plugin jar file?

Try the URLClassLoader (http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLClassLoader.html) you can use any url, including file:///c:/some/path/my.jar. Classloaders are funny things. Once a classloader has loaded a class, you cannot unload the jar file. You have to delete the classloader and create a new one. Most hot deployment containers, like tomcat, use this mechanism. You’‘ll have to use reflection to get at the class in the classloader, so it’'s advisable that you create a well document interface for the objects in the jar file, that way you can develop with a well known type.