I have a jar file, which I dynamically load during execution of my java file (say my.java).
I do it this way:
File newFile = new File("path");
JarFile newJar= new JarFile(newFile);
Now there is a particular java file inside this jar, which I know the name of (say known.class).
I want create an object of this known.class, and call a method inside it from my.java.
I am not sure how to go about this. Can any one help?
I tried looking online, but didn’t find anything helpful.
Thanks.
You need a
.classfile (compiled java code) inside the jar, not a.javafile. If you have this, add the .jar to your classpath, or to one of the directories in your classpath, and then you can simply reference the Object from your Java code.Ie:
Here’s how your specify the jar in the classpath:
Edit: Since you don’t want to change the classpath, try something like this: