In my project, I have to implement a system of extensions : loadable classes
all derived from an abstract class defined in my main project.
I am using netbeans.
So I have created another project beside my main project (which will load
the extension), and I have defined in the project properties, libraries
folder, the compile time libraries to be my main project jar file, and the
same in the run, compile test and run test panel.
In my main project, I load the class file witht he following code :
CExtClassLoader loader=new CExtClassLoader(extPath);
Class c=Class.forName(extName, false, loader);
CEditExtension object = (CEditExtension)c.newInstance();
catch (LinkageError e)
catch (ClassNotFoundException e)
catch (InstantiationException e)
catch (IllegalAccessException e)
My class loader locates the class file in the extension folder, creates a
byte array and calls defineClass as explained in the javadoc. It
successfully loads the file.
The problem is that I have a IllegalAccessException in the Class.forName
method. I do not know why. The doc on this exception says :
"An IllegalAccessException is thrown when an application tries to
reflectively create an instance (other than an array), set or get a field,
or invoke a method, but the currently executing method does not have access
to the definition of the specified class, field, method or constructor."
So obviously, it does not find something when instanciating my extension. It
is true that the extension imports some of the packages defined in my main
project. But it compiles fine (as soon as I declared the jar file as a
What am I doing wrong?
Thank you for your input.