I want to add a jar File to my project\'s classpath dynamically using java code if it is possible , I want to use external jar files and load their classes the execute them as B
You can try something like this, but it requires you to know, where exactly your JARs
are located.
URLClassLoader cl = URLClassLoader.newInstance(new URL[] {myJarFiles});
Class myClass = cl.loadClass("com.mycomp.proj.myclass");
Method printMeMethod = myClass.getMethod("printMe", new Class[] {String.class, String.class});
Object myClassObj = myClass.newInstance();
Object response = printMeMethod.invoke(myClassObj, "String1", "String2");