How to load JAR files dynamically at Runtime?

前端 未结 20 3203
伪装坚强ぢ
伪装坚强ぢ 2020-11-21 05:15

Why is it so hard to do this in Java? If you want to have any kind of module system you need to be able to load JAR files dynamically. I\'m told there\'s a way of doing it b

20条回答
  •  长情又很酷
    2020-11-21 05:48

    If you are working on Android, the following code works:

    String jarFile = "path/to/jarfile.jar";
    DexClassLoader classLoader = new DexClassLoader(jarFile, "/data/data/" + context.getPackageName() + "/", null, getClass().getClassLoader());
    Class myClass = classLoader.loadClass("MyClass");
    

提交回复
热议问题