0

I am currently working on an app that supports plug ins. The plug ins are located in a root folder called modules as jar files. My main application loads all the jars located in the modules folder using the java service loader

Application
    src
    modules

My modules have the following folder structure:

PlugIn
    src
    resources

Images used by the plug in are stored in the resources folder. My problem is I cannot seem to load these image files no matter what i do. I have tried using getClass().getResource() etc like what the previous posts suggested but with no luck. Can anybody suggest a possible solution to this?

EDIT

The plug ins are the ones that load the resources. The main app does not touch the plug in's resources

MykelXIII
  • 1,085
  • 1
  • 8
  • 16

1 Answers1

1

You should have your resources inside the src

PlugIn
     src
         resources
                image.png

Then use

getClass().getResource("/resources/image.png");

When you build, the resources should get loaded to your class path

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • Is there a way to not include it in the src folder? I tried converting the resource folder as a source folder but didn't work – MykelXIII Feb 03 '14 at 15:04
  • _"Is there a way to not include it in the src folder?"_ This is where you want it. Not necessarily where I have it, but yea in the src. An embedded resource will get loaded from the class path. And if the resources is in the src it will get built into the class path. – Paul Samsotha Feb 03 '14 at 15:07
  • So your saying the proper place for the folder is in the src folder? – MykelXIII Feb 03 '14 at 15:18
  • 1
    For embedded resources, yes. Though being a direct child of the src isn't the only way. I use Maven and I put the `resources` in `src/main`. And not just that, I put a package in that `resources`. The same package name as the package for my classes. When Maven builds, all the resources will get loaded into the same package as the class files. I think this is a pretty standard way to do it. With Maven at least. – Paul Samsotha Feb 03 '14 at 15:23