Whatever message this page gives is out now! Go check it out!
THIS.javaSettings = {LoadPaths = [".\java_lib\",".\java\myjar.jar"], loadColdFusionClassPath = true, reloadOnChange = false} |
| Parameter | Description |
loadPaths | An array of paths to the directories that contain Java classes or JAR files.You can also provide the path to a JAR or a class. If the paths are not resolved, an error occurs. |
loadColdFusionClassPath | Indicates whether to load the classes from the ColdFusion lib directory. The default value is false. |
reloadOnChange | Indicates whether to reload the updated classes and JARs dynamically, without restarting ColdFusion. The default value is false. |
THIS.javaSettings = {LoadPaths = [".\java_lib\",".\java\myjar.jar"], loadColdFusionClassPath = true, reloadOnChange= true, watchInterval = 100, watchExtensions = "jar,class,xml"} |
| Parameter | Description |
loadPaths | An array of paths to the directories that contain Java classes or JAR files.You can also provide the path to a JAR or a class. If the paths are not resolved, an error occurs. |
loadColdFusionClassPath | Indicates whether to load the classes from the ColdFusion lib directory. The default value is false. |
reloadOnChange | Indicates whether to reload the updated classes and JARs dynamically, without restarting ColdFusion. The default value is false. |
watchInterval | Specifies the time interval in seconds after which to verify any change in the class files or JAR files. This attribute is applicable only if the reloadOnChange attribute is set to true. The default value is 60 seconds. |
watchExtensions | Specifies the extensions of the files to monitor for changes. By default, only .class and .jar files are monitored. |
public class Test { public String testJava() { return "Hello Java!!"; } } |
<cfset THIS.javaSettings = {LoadPaths = ["/myJava/lib"],reloadOnChange=true,watchInterval=30}/> |
/myJava/lib |
<cfobject type="java" class="Test" name="myObj"> <cfset y = myObj.init()> <cfoutput > #y.testJava()# </cfoutput> |
CFCProxy(String fully-qualified-path-of-CFC-file) |
CFCProxy(String fully-qualified-path-of-CFC-file name-value-pairs) |
import coldfusion.cfc.CFCProxy; public class CFCInvoker { public String directInvoke(String cfcPath) { String myMessage = ""; try { CFCProxy myCFC = new CFCProxy(cfcPath, true); Object[] myArgs = { "Hello" }; myMessage = (String)myCFC.invoke("getData", myArgs); } catch (Throwable e) { e.printStackTrace(); } return myMessage; } } |
<cfcomponent> <cffunction name="getData" returntype="string"> <cfargument name="msg" required="Yes"> <cfreturn msg & "Java" /> </cffunction> </cfcomponent> |
THIS.javaSettings = {LoadPaths = ["/lib"],reloadOnChange= true,loadColdFusionClassPath=true}; |
<cfobject action="create" type="java" class="CFCInvoker" name="x"> <cfset cfcPath = "C:\ColdFusion10\cfusion\wwwroot\Project\name.cfc"/> <cfset y = x.directInvoke2(cfcPath)> <cfoutput>#y#</cfoutput> |
createDynamicProxy("fullyQualifiedNameOfCFC", ["interfaceName"]); |
public interface MyInterface { public String sayHello(); } |
public class InvokeHelloProxy { private MyInterface myInterface; public InvokeHelloProxy(MyInterface x) { this.myInterface = x; } public String invokeHello() { return myInterface.sayHello(); } } |
<cfcomponent> <cffunction name="sayHello" returntype="string"> <cfreturn "Hello World!!!!"> </cffunction> </cfcomponent> |
<cfset THIS.javaSettings = {LoadPaths = ["/lib"],reloadOnChange=true,watchInterval=10}/> |
<cfset dynInstnace = createDynamicProxy("cfc.HelloWorld", ["MyInterface"])> <cfset x = createObject("java","InvokeHelloProxy").init(dynInstnace)> <cfset y = x.invokeHello()> <cfoutput>#y#</cfoutput> |
<cfset instance=new cfc.helloWorld()> <cfset dynInstnace = createDynamicProxy(instance, ["MyInterface"])> <cfset x = createObject("java","InvokeHelloProxy").init(dynInstnace)> <cfset y = x.invokeHello()> <cfoutput>#y#</cfoutput> |
java
public interface StateChangeListener {
void onStateChange(State oldState, State newState);
}StateChangeListener or Predicate<String>).onStateChange, test, or run) to determine the expected arguments.createDynamicProxy() manually for common functional‑interface use cases.// Java interface
public interface StateChangeListener {
void onStateChange(State oldState, State newState);
}
// Java class that accepts the interface
public class StateOwner {
public void addStateListener(StateChangeListener listener) {
// ...
}
} <cfscript>
// Create the Java object
stateOwner = createObject("java", "com.example.StateOwner");
// Pass a CFML function where Java expects a StateChangeListener
stateOwner.addStateListener( function(oldState, newState) {
writeOutput(
"State changed from " & oldState.toString() &
" to " & newState.toString() & "<br>"
);
});
</cfscript>
<cfscript>
// Create a Java ArrayList
list = createObject("java", "java.util.ArrayList").init();
list.add("apple");
list.add("banana");
list.add("chery");
// Get Java stream from the list
stream = list.stream();
// Apply filter and collect results
collector = createObject("java", "java.util.stream.Collectors");
upperList = stream
.filter(input => { return input.length() == 6; })
.collect(collector.toList());
// Validate output without writeDump
writeOutput(upperList.size() & "|" & upperList.contains("banana"));
// Output: 1|true
</cfscript>input => { return input.length() == 6; } is a CFML lambda expression.java.util.function.Predicate<String> for filter.Predicate interface and calls the CFML code when Java invokes test.forEach (for example, stream.forEach(item => { ... }))map (for example, stream.map(item => { return item.toUpperCase(); }))java.util.function package.Runnable:<cfscript>
executor = createObject("java", "com.example.Executor");
// Java method: public void executeAsync(Runnable task)
executor.executeAsync( function() {
writeOutput("Running in background<br>");
});
</cfscript>Runnable implementation and invokes it when Java calls run().<cfscript>
CompletableFuture = createObject("java", "java.util.concurrent.CompletableFuture");
future = CompletableFuture
.supplyAsync(() => { return "hello world"; })
.thenApply(val => { return uCase(val); })
.thenApply(val => { return len(val); });
writeOutput(future.get());
</cfscript>