Scala - Dynamic object/class loading
In Java, I load external class (in .jar file) by this way: ClassLoader classLoader = new URLClassLoader(new URL[] { new File("module.jar").toURI().toURL()}); Class clazz = classLoader.loadClass("my.class.name"); Object instance = clazz.newInstance(); //check and cast to an interface, then use it if (instance instanceof MyInterface) ... And it works fine. ==================== Now I want to do the same thing in Scala. I have a trait named Module ( Module.scala ): trait Module { def name: String } object Module { lazy val ModuleClassName = "my.module.ExModule" } I write a module extending Module