I want to load Java class using URLClassLoader and invoke method main. The code below gives an error at the last line and I can not figure out how to fix it.
(def classloader (URLClassLoader. (into-array files))) (def classname "example.Test") (def clazz (.. classloader (loadClass classname))) ; I assume not the most effective way to get method "main" ; additional feedback appreciated (def method (first (filter #(= (. % getName) "main") (. clazz getMethods)))) (def args (make-array String 1)) ; specify single command line argument for method main(String[]args) (aset args 0 "my-file") ; attempt to invoke static method using Java reflection API fails. (. method invoke nil args)
Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch, compiling:
Please note that the class is not otherwise available in the default classloader, so
(example.Test/main "myfile")
would fail.
Thank you, Pavel