N
Nuno
Hello to all,
I'm new on java but i'm old on c++, and i'm now developing in java.
And i want to built a solution in java that implements the normal
logic of plugins in windows. That is a list of dll files in a
predefined folder and a program that loads each dll in the startup
process, and the rest is history... all the dll's implement the same
interface bla bla bla
And now i want to know what is the best solution to do the same thing
but in java environment. I've already tested the ClassLoader object in
java and it works fine to load a certain package, example:
String classdir = "file:/D:/tmpimp/java/tests/workspace/
com.teste.plugin/";
String classname = "com.teste.Math";
try
{
ClassLoader loader = new URLClassLoader(new URL[] { new
URL(classdir) });
Class c = loader.loadClass(classname);
IMath o = (IMath) c.newInstance();
int a = 1;
int b = 2;
int result = o.add(a, b);
String.format("%d + %d = %d", a, b, result));
}
catch (Exception ex)
{
System.out.println(ex.toString());
}
My question is to know witch is the best way to do this, the plugin
thing, and if this is a good way (with the ClassLoader object) then
what is the best way to find the packages in the file system, is using
a xml file or read a predetermine folder with all the packages.
Thanks
Nuno
I'm new on java but i'm old on c++, and i'm now developing in java.
And i want to built a solution in java that implements the normal
logic of plugins in windows. That is a list of dll files in a
predefined folder and a program that loads each dll in the startup
process, and the rest is history... all the dll's implement the same
interface bla bla bla
And now i want to know what is the best solution to do the same thing
but in java environment. I've already tested the ClassLoader object in
java and it works fine to load a certain package, example:
String classdir = "file:/D:/tmpimp/java/tests/workspace/
com.teste.plugin/";
String classname = "com.teste.Math";
try
{
ClassLoader loader = new URLClassLoader(new URL[] { new
URL(classdir) });
Class c = loader.loadClass(classname);
IMath o = (IMath) c.newInstance();
int a = 1;
int b = 2;
int result = o.add(a, b);
String.format("%d + %d = %d", a, b, result));
}
catch (Exception ex)
{
System.out.println(ex.toString());
}
My question is to know witch is the best way to do this, the plugin
thing, and if this is a good way (with the ClassLoader object) then
what is the best way to find the packages in the file system, is using
a xml file or read a predetermine folder with all the packages.
Thanks
Nuno