Java Class.forName() from distant directory

前端 未结 3 1800
夕颜
夕颜 2020-12-01 22:29

I am currently loading Java classes using Class.forName() to load it.

clazz = Class.forName(\"interfaces.MyClass\");

But now I

3条回答
  •  难免孤独
    2020-12-01 23:17

    Either the directory is in the classpath, and you can use Class.forName() (which only accepts fuly qualified name classes, and not -cp command line options), or it's not in the classpath and you should then use a custom class loader.

    You're not saying what you really want to do (why are you loading classes dynamically), but your best bet is to have the directory in the classpath.

提交回复
热议问题