More information about JarClassLoader:
Seems that the unloadClass()-method don't work correct.
But possible that it depends on the ClassLoader itself, which JarClassLoader is based on.
I have now read in the internet and as answer from the author of JarClassLoader, that changing a class in one JCL-instance is not possible.
What I mean with it:
For example, you have three external jar-files:
- mygui-1.2.jar
- mynet-0.4.jar
- mydb-1.1.jar
All jars are loaded with JarClassLoader (or if you doing it your own way with URLClassLoader or ClassLoader).
And for example you program makes use of some of the classes in each of the jar-files.
When you then plan, to change one of that jar-files with an other one (for example mynet-0.4.jar to mynet-0.5.jar) in a running system (without restarting the java-program), then it is not possible, to unload the net-classes and reload the newer version of it.
The only way, to load a new version of the same class is, to create a new instance of JarClassLoader.
So, if you have an instance of JarClassLoader called "jclWhatThe" and want to change the loaded mynet-0.4.jar to mynet-0.5.jar, then you have to remove all instances of classes, which are in mygui-1.2.jar, mynet-0.4.jar and mydb-1.1.jar.
After that creating a new instance of JarClassLoader (for example, writing "jclWhatThe = New JarClassLoader()" again), loading mygui-.1.2.jar and mydb-1.1.jar again and loading the new mynet-0.5.jar.
So again:
WIth one instance of a ClassLoader you can only add classes. You can not remove or replace them.
If you want to remove or replace a class, then you have to create a new ClassLoader-instance, which needed be again loading all classes.
Thats the information I currently have.
And btw to the JarClassLoader-license. Currently in the head of that files is only the LGPL-mentioned. But the next time the author will write there, what on github stands, that JarClassLoader is under the LGPL and ApacheLicense.
Greatings
theuserbl
Roger on the license, I'll include the notice next time.
I'm getting different results from you, when running the JCL2. The original JCL.jar works fine.
In JCL2, if the project is Maked, and the executable is run, then no problem running the following:
myArgs = args
System.out.println( "Here we go..." )
System.out.println( "Creating instance of JarClassLoader" )
jclWhatThe = New JarClassLoader()
System.out.println( "Adding the jar" )
jclWhatThe.add( "c:\Projects_Programming\Jabaco\ExternalJars\WhattheWorld.jar" )
System.out.println( "Loading the class" )
oWhatThe = jclWhatThe.loadClass( "WhattheWorld" ).newInstance()
System.out.println( "Invoking sayWhatthe" )
CallByName oWhatThe, "sayWhatthe"
System.out.println( "Unloading the class" )
jclWhatThe.unloadClass( "WhattheWorld" )
System.out.println( "...Finished" )
, but if it's run in the IDE, then there's a NullPointerException at
oWhatThe = jclWhatThe.loadClass( "WhattheWorld" ).newInstance()
Both In and Out of the IDE, using JCL2, there's a NullPointerException at
Dim cls As java#lang#Class = oWhatThe.getClass()
Regarding the prohibition about reloading a class, that's fine. This is useful enough, even with that limitation.
Thanks, theuserbl. Most of it's working fine, will continue to experiment.