2

I have written a program which manages a plugin which is provided as jar.

I load the plugin classes using an URLClassLoader which works as it's supposed to. I had added some resources (XML file) which are stored in the plugin jar.

If I invoke a method that doesn't use resources, everything works fine, but if I invoke a method that uses resources I get a FileNotFoundException.

BSMP
  • 4,596
  • 8
  • 33
  • 44
Garsov
  • 31
  • 6
  • 2
    Posting some of your code would be helpful – mcraenich May 10 '17 at 16:59
  • invoke() method :load class , getResourceAsStream():load resource ,is there any way to relate these two method , i want that invoke method reference to getResourceAsStream Method – Garsov May 10 '17 at 17:59

1 Answers1

0

The resources packaged inside your plugin jar file are loaded by your URLClassLoader. So to access those resources, you should use that particular URLClassLoader instance to load them.

Eg:

URL[] urls = ...//urls to jar classes and resources
URLClassLoader uClassLoader = new URLClassLoader(urls);
Class loadedClass = uClassLoader.loadClass("CLASS_NAME");

To get the resource present in the jar,

loadedClass.getClassLoader().getResource()

Note, here the URLClassLoader instance is used to load the resources.

For more details on loading the resources:

Hope this solves your issue.

code
  • 2,283
  • 2
  • 19
  • 27