1

I am designing a web application with plug able component architecture (plugins). My requirement is to add new plugin jar (classes) into application without restarting the application, it should be dropped in web application's lib or plugin directory and application should able to pick it up.

I tried this with tomcat server but it can not load the jar file dropped into its lib directory once its started.

Can anyone suggest a best way to do this ?

  • 1
    Better use OSGI for this purpose. Its able to load and unload Jars/Packages/Classes from your classpath at runtime. You can even define them in a repository where they can be searched and downloaded, without the need to know their names. – Stefan Sep 30 '14 at 07:26
  • I was just about to add this pointer too. Main argument: You *don't want* to invent, implement and maintain yet another component framework when there's one that has nailed it all, unless it's for academic entertainment. But even then, I consider this problem to be solved very well in OSGI – Olaf Kock Sep 30 '14 at 07:31

1 Answers1

0

your attempt is good what ever you are trying to do can help you by below code

URL urls [] = {};

JarFileLoader cl = new JarFileLoader (urls);

cl.addFile ("/opt/mysql-connector-java-5.0.4/mysql-connector-java-5.0.4-bin.jar");

System.out.println ("attempt...");

cl.loadClass ("org.gjt.mm.mysql.Driver");

System.out.println ("Success!");

I hope this will help you

The JVM searches for and loads classes in this order:

Bootstrap classes, which are classes that comprise the Java platform, including the classes in rt.jar and several other important JAR files.

Extension classes, which use the Java Extension mechanism. These classes are bundled as JAR files and located in the extensions directory.

User classes are classes that are defined by developers and third parties and that do not take advantage of the extension mechanism.

santhosh
  • 484
  • 3
  • 10
  • Thanks Santosh, but in my case i may not be able to mention jarfile name or even class name, because at run time it could be anything, what i am doing is have annotated each plugin class with @Plugin annotation and that's the only thing my plugin scan logic is working around.What i can do is trigger this plugin scan logic at regular interval. –  Sep 30 '14 at 05:14