dimanche 17 juin 2018

How to give input for scanner class in reflection method for dynamic code execution

I was doing a project which is a web compiler and I am using reflection method for code execution. but I am not able to pass any value for scanner class in order to read from the java program. how can I pass a value for scanner class using method of reflection api

  String paramsObj[] = {"hellooo"};
  File f = new File("/location/to/class");
  URL[] cp = {f.toURI().toURL()};
  URLClassLoader urlcl = new URLClassLoader(cp);
  Class clazz = urlcl.loadClass(filename.trim());
  Object iClass = clazz.newInstance();
  Class[] argTypes = new Class[] { String[].class };
  String[] mainArgs ={"Abcd","defg"};
  Method thisMethod = clazz.getMethod("main",argTypes);
  thisMethod.invoke(null,(Object)mainArgs);

this is how i am calling main method , can anyone please help me to solve this ...?





Aucun commentaire:

Enregistrer un commentaire