Search code examples
javaserviceloader

Problems using image resources of plug in jars


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


Solution

  • 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