Loading of jars ...during run time for enterprise app.
I apologize for being a bit naive. I have been given the task to come up with a framework where Jar files containing classes have to be compiled and loaded on demand.
The jar files will contain code written by third party company. I have to come up with a solution where I load these class into memory.
I am trying to gain a solid understanding of class loaders, although I feel there is much more required to be done than just writing class loader for aforesaid problem.
Thanks for any lead provided in steps to follow for solving this problem.
Message was edited by:
deepinder_m
I am hitting a deadline soon to solve this problem.So any help will be appreciated.
# 1
> I have to come up with a framework where Jar files
> containing classes have to be compiled and loaded on
> demand.
Compiled?
Do you mean jar files containing Java source files?
> The jar files will contain code written by third
> party company. I have to come up with a solution
> where I load these class into memory.
Compiled to memory, then loaded directly from memory
or could you write the classes to a local temporary disk location?
> I am trying to gain a solid understanding of class
> loaders, although I feel there is much more required
> to be done than just writing class loader for
> aforesaid problem.
Yes, you need a new class loader (URLClassLoader?) that can be discarded
in order to 'forget' about a 3rd party classes again - giving you the ability to re-load a class.
> Thanks for any lead provided in steps to follow for
> solving this problem.
> I am hitting a deadline soon to solve this problem.So
> any help will be appreciated.
Your deadline is not relevant.
# 2
>Compiled?
>Do you mean jar files containing Java source files?
no ...jar files will contain java class files
>Compiled to memory, then loaded directly from memory
>or could you write the classes to a local temporary disk location?
yes compiled to memory then loaded directly from memory
>Yes, you need a new class loader (URLClassLoader?) that can be >discarded
>in order to 'forget' about a 3rd party classes again - giving you the ability to >re-load a class.
I have used the URLClassLoader, although I have to use
Thread.currentThread().getContextClassLoader().loadClass("package1.test.HelloWorld");
instead of new HelloWorld() for using my class loader after setting it as default loader.
There seems to be a problem with linking which I cannot circumvent....
# 3
> >Compiled?
> >Do you mean jar files containing Java source files?
>
> no ...jar files will contain java class files
>
> >Compiled to memory, then loaded directly from memory
> >or could you write the classes to a local temporary disk location?
>
> yes compiled to memory then loaded directly from memory
Well, which is it?
Do you have Java class files in your jar archive (no need to compile)
OR
do you have Java source files in your jar archive (which will need to be compiled)?
# 4
jar files will contain classes..(no need to compile)Message was edited by: deepinder_mI am not able to use new HelloWorld()....instead I have to load the jar file and explicitly call my custom loader ...passing it the fqcn package1.test.HelloWorld