-
Notifications
You must be signed in to change notification settings - Fork 0
Class Loading
This is the core function of JavaLoader. To take a Java Library that is stored on your file system, and make it available for you to use in your ColdFusion application without having to load it into the ColdFusion class path.
- ColdFusion 7, 8 or 9
- Java 1.4+
To use JavaLoader to load classes that are stored in a file path, you can use it like so:
createObject("component", "javaloader.JavaLoader").init(loadPaths [,loadColdFusionClassPath] [,parentClassLoader]);
There are three arguments for classloading that are possible to use to configure how and what the JavaLoader loads.
An array of directories of classes, or paths to .jar files to load.
An example would be:
loadPaths = ArrayNew(1);
loadPaths[1] = expandPath("icu4j.jar");
loadPaths[2] = expandPath("log4j.jar");
Defaults to: false
Loads the ColdFusion libraries with the loaded libraries.
This used to be on by default, however now you must implicitly set it to be true if you wish to access any of the libraries that ColdFusion loads at application start up.
Defaults to: null
(Expert use only) The parent java.lang.ClassLoader to set when creating the URLClassLoader.
Note - when setting loadColdFusionClassPath to 'true', this value is overwritten with the ColdFusion classloader.
To create an instance of a Java Class, you then only need to call:
javaloader.create(className).init(arg1, arg2...);
The name of the Java Class to create.
This works exactly the same as createObject("java", className), such that simply calling create(className) gives you access to the static properties of the class, but to get an instance through calling the Constructor you are required to call create(className).init();
For example:
javaloader.create("org.apache.log4j.Logger").init("my log");