Jump to content
Excelsior Forums
Sign in to follow this  

Loading resources in combination with reflection

Recommended Posts

I have a problem loading resources from classes that were instantiated using reflection.

dll: Test.class + image.gif
exe: Main.class

(Test.class loads image.gif)

When I just instantiate the Test-class from Main, it can load the resource perfectly. When I instantiate Test using reflection, the resource is not found.

I tried binding the resource to the exe and then, using reflection, the resource is found also.

dll: Test.class
exe: Main.class + image.gif

We need reflection because our application is built from modules and it should work smoothly, even when a few modules are missing. Also, resources should be together with the code using it, so binding all resources to the exe is not a solution either.

Is there a way to tell the application which dll contains the resources, or is this problem inherently related to reflection?

Thanks in advance.

Share this post

Link to post
Share on other sites


It seems to me that the problem in the java.class.path property value.

This property enumerates jar files (and directories) where the resources should be searched. This property is defined at the very start-up. JET automatically enumerates all jar files that where bound to all components (dlls, exes) that are loaded at startup. If the dll is loaded later (via class lookup using reflection), it is late to include its resources into classpath.

You can manually define java.class.path property in the exe. Enumerate all resource jars, including those from dlls in the property value. So, for example, if you have a.jar in exe and b.jar in dll, set java.class.path property in exe to a.jar;b.jar. You can do it in JET Control Panel or in JetPackII.


Share this post

Link to post
Share on other sites

Thanks for your reply.

I experimented some more. I added all jars to the java.class.path property (specified in the .prj-file of the exe). Now my application only runs when the jar-files are present in the directory of the exe.

Did I miss something and should it work without the jars, just the dll's and exe? Or do I need to make a jar that contains my resources, refer to it in the java.class.path-property, and distribute this jar along with my application?

Thanks in advance,


Share this post

Link to post
Share on other sites
Sign in to follow this