Plugins or modules

R

RomanoRega

I have to build a java aplication which has to deal with modules
(plugin if you want).
Those have to be just simple class that the application has to find in a
filesystem directory , load and eventually use.
Is this possible at all?

Thanks for every advice
 
W

Will Hartung

RomanoRega said:
I have to build a java aplication which has to deal with modules
(plugin if you want).
Those have to be just simple class that the application has to find in a
filesystem directory , load and eventually use.
Is this possible at all?

The simpest way to go is to place the compiled class file within the
classpath of the Java app, and then using the
Class.forName("full.class.name").

public YourInterface newThing(String className)
throws Exception
{
Class newClass = Class.forName(className);
YourInterface theInstance = (YourInterface)newClass.newInstance();

return theInstance;
}

If the class file is not in your classpath already (or in some other
medium), then you need to play with ClassLoaders, which can complicate the
issue.

Regards,

Will Hartung
([email protected])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top