Loading java classes from an arbitrary location
This problem began with me just wanting to use my pojo’s and not
have to worry about where they were. With a little help from this post by spike
i was able to get around that problem. With spikes code you can
load your classes from any aribtrary location. Which is a cool
thing by me. I quickly turned his code into a cfc so that I coudl
easily pass in the path and class and have it return the object for
me. I was concerned though that when a class loaded by my class
was called it would look on the class path of cf. This was not
the case, it loaded it fine, but I found another problem. When I
used the example of a User object and a Phone object i found that the
phone object didnt get recognized as Phone. On my user object I
have a setPhone( Phone myPhone) method. So I create my phone
object, set its properties. Create a user object and pass in the
phone object to set phone. This would throw an error that it was
not the right type. After talking with barney for a bit he asked
if I was using the same instance of my classLoader to load user and
phone. I was not. My classLoader had one function and it
created the object and ended its life for each call. So to fix
this I created an init method which took the path to your
classes. In addition to init I created a load method which just
took the class you wanted. So now you create your classLoader for
a particular set of files ( you can load files in packages ie.
net.simb.User ) and call load on it for all the objects you need.
==========================
Update: Here is the download for the classLoader.cfc I created.
