Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
Public Sub main(ByJava args() As String) Dim myArgs() As String Dim jclWhatThe As JarClassLoader Dim oWhatThe As Object 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( "WhattheWorld.jar" ) System.out.println( "Loading the class" ) oWhatThe = jclWhatThe.loadClass( "Module1" ).newInstance() CallByName oWhatThe, "showAllMethods" 'showAllMethods() 'showAllMethods("java.lang.String") End Sub Public Sub showAllMethods() 'Public Sub showAllMethods(ClassName As String ) 'Dim ClassName As String = "java.lang.String" Dim ClassName As String = "WhattheWorld" Dim cls As java#lang#Class = java#lang#Class.forName(ClassName) Dim mets() As java#lang#reflect#Method 'mets() = cls.getMethods mets() = cls.getDeclaredMethods Int i For i = 0 To Ubound(mets) System.out.println(mets(i)) Next i End Sub |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Public Sub main(ByJava args() As String) Dim myArgs() As String Dim jclWhatThe As JarClassLoader Dim oWhatThe As Object 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( "WhattheWorld.jar" ) System.out.println( "Loading the class" ) oWhatThe = jclWhatThe.loadClass( "WhattheWorld" ).newInstance() System.out.println( "Show all methods" ) Dim cls As java#lang#Class = oWhatThe.getClass Dim mets() As java#lang#reflect#Method 'mets() = cls.getMethods mets() = cls.getDeclaredMethods Int i For i = 0 To Ubound(mets) System.out.println(mets(i)) Next i End Sub |
Yep, I'm sure the source for JCL makes use of native reflection, but it's packaged in a way that makes it easier to operate on modules which aren't initially loaded, or in the class path.Ok, it is really normal reflection.
Jabaco Source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Public Sub main(ByJava args() As String) Dim myArgs() As String Dim jclWhatThe As JarClassLoader Dim oWhatThe As Object 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( "WhattheWorld.jar" ) System.out.println( "Loading the class" ) oWhatThe = jclWhatThe.loadClass( "WhattheWorld" ).newInstance() System.out.println( "Show all methods" ) Dim cls As java#lang#Class = oWhatThe.getClass Dim mets() As java#lang#reflect#Method 'mets() = cls.getMethods mets() = cls.getDeclaredMethods Int i For i = 0 To Ubound(mets) System.out.println(mets(i)) Next i End Sub
Thanks for removing the log requirements, will give it a try.
Will play with it today, thanks theuserbl.Thanks for removing the log requirements, will give it a try.
I have now added a compiled version of JCL version2 from github.
It is at the beginning without the logging, but on the other side, it is itself a lot of bigger.
On github stands, that version 2 is faster, have more functions and so on.
So, here is version 2. The jar-file in the the zip-file, because it is not possible to upload a jar-file in this forum.
Greatings
theuserbl
Roger on the license, I'll include the notice next time.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
This post has been edited 2 times, last edit by "jbExplorer" (Jan 4th 2014, 3:16am)