In memory jar / class file execution

前端 未结 4 1639
一向
一向 2021-02-10 19:13

I have a jar file (say app.jar) in a certain location available as a file/stream from an http server. The problem is that app.jar is itself a frequently updated jar file being

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-10 20:08

    I will suggest have a look at http://jcloader.sourceforge.net/

    This has better flexibility and is quite feature rich.

      JarClassLoader jcl = new JarClassLoader();
    
      //Loading classes from different sources
      jcl.add("myjar.jar");
      jcl.add(new URL("http://myserver.com/myjar.jar"));
      jcl.add(new FileInputStream("myotherjar.jar"));
      jcl.add("myclassfolder/");
    
      //Recursively load all jar files in the folder/sub-folder(s)
      jcl.add("myjarlib/");
    
      JclObjectFactory factory = JclObjectFactory.getInstance();
    
      //Create object of loaded class
      Object obj = factory.create(jcl, "mypack.MyClass");
    

提交回复
热议问题