createJavaObject(directory)
Last updated October 19, 2004
Version: 1 | Requires: ColdFusion MX | Library: UtilityLib
Description:
Instantiates Java objects in virtual paths so you do not need to change the classpath for your application.
Return Values:
Returns a Java object.
Example:
loader = createJavaObject("./");
helloWorld = loader.loadClass("GpgTool").newInstance();
</cfscript>
<cfdump var="#helloWorld#">
Parameters:
| Name | Description | Required |
|---|---|---|
| directory | Directory where the class can be found. | Yes |
Full UDF Source:
<cfscript>
/**
* Allows one to use virtual paths to Java objects.
* Returns a Java object for a given virtual path.
* This allows you to place your Java class files
* anywhere you want. Based on Stephen Milligan's blog entry at http://www.spike.org.uk/blog/index.cfm?data=20040603#EBB52433-D565-E33F-353D2664926C59B5
*
* @param directory Directory where the class can be found. (Required)
* @return Returns a Java object.
* @author Wayne Graham (wsgrah@wm.edu)
* @version 1, October 19, 2004
*/
function createJavaObject(directory){
var URLObject = createObject("java", "java.net.URL");
var ArrayClass = createObject("java","java.lang.reflect.Array");
var loader = createObject("java","java.net.URLClassLoader");
var URLArray = "";
directory = replace(expandPath(directory), "\", "/", "all");
URLObject.init("file:" & directory);
URLArray = createObject("java", "java.lang.reflect.Array").newInstance(URLObject.getClass(), 1);
ArrayClass.set(URLArray,0,URLObject);
return loader.init(URLArray);
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
11 day(s) ago
Will Belden added
longTime
17 day(s) ago
James Sleeman added
quickSort
27 day(s) ago
Ben Forta added
GetHostAddress
30 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)