Jump to content
Excelsior Forums

Class.forName within dynamically-loaded class results in ClassNotFoundException

Recommended Posts

Hello everyone. Hope all well at Excelsior!

We have an application, compiled through Jet, which we allow our customers to extend by writing plugins. Those plugins are class files (since our customers do not have a Jet installation).

Now, our application locates their class by using Class.forName(pluginclassname) - this works fine.

This plugin now needs to use functionality of the application for which it creates instances of the application's classes. The customer's plugin cannot directly reference the application's classes since all application classes are embedded within the .exe and thus javac cannot find it. Hence we have requested the customer to use Class.forName(applicationclass), which unfortunately does not work - it results in a ClassNotFoundException.

My guess is that Jet is stripping the names of the classes when building the native executable. If so, how can i tell it to retain names for specific classes? Or is the solution more complex?

Please note that we have a valid support contract.

Best Regards,
Sushant A

Share this post

Link to post
Share on other sites


Looks like it was my mistake - the application classes implemented interfaces which were not present on the classpath during the compilation of the executable.

To anyone one else facing this issue:
* Create interfaces containing the public functions of your internal classes which expose functionality.
* Ensure that your internal classes are implementing those interfaces.
* Compile using Jet, specifying both the internal classes and the interfaces on its classpath.
* Once the executable is created, ship the executable and the interfaces to your customer.

Your customer can now use 
   Interfacename f = Class.forName(internalclassname).newInstance(); 
to locate and instantiate objects of your internal classes, and call functions within it.

To compile their plugin, they will have to add the interfaces to their javac's classpath for compilation on Sun Java. But the interfaces will not be required during execution, since the executable already contains native versions within the exe.

Hope this helps.

Sushant A

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now