问题
I'm trying to use ColdFusion 10's ability to load custom Java classes and watch for changes. I have been able to successfully load Java classes but they do not get updated when they are changed and recompiled. The following is an example using both ColdFusion 10's java loading and the JavaLoader library; the JavaLoader library works, ColdFusion 10 doesn't.
application.cfc
<cfcomponent accessors="true" output="false" persistent="false">
<cfscript>
THIS.mappings["/javaloader"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "javaloader";
THIS.javaSettings = {LoadPaths = [".\java\bin"], loadColdFusionClassPath = true, reloadOnChanges = true, watchInterval=5};
</cfscript>
</cfcomponent>
Index.cfm
<html>
<head><title>Hello World</title></head>
<body>
<h2>Echo example</h2>
<cfset binDir = expandPath("java/bin")>
<cfset libDir = expandPath("java/lib")>
<cfset jars = directoryList(libDir)>
<cfset arrayAppend(jars,binDir)>
<cfset loader = createObject("component","javaloader.JavaLoader").init(jars)>
<!--- Using the Java class loaded with javaloader--->
<cfset hello=loader.create("TestRT")>
<cfoutput>Hi #hello.echo("marc")#</cfoutput>
<br>
<!--- Using the Java class loaded with ColdFusion10--->
<cfset hello2 = createObject("java","TestRT")>
<cfoutput>Hi #hello2.echo("marc")#</cfoutput>
<h2>End</h2>
</body>
</html>
TestRT.java
public class TestRT {
public static String echo(String e){
return "Hiye "; //+ response;
}
}
Project structure:
Output:
As you can see the JavaLoader library has picked up the updated "hiye" but ColdFusion 10 is still using the old version with "hiy". Why is ColdFusion not picking up the change? I have reloadOnChanges = true, watchInterval=5
set
回答1:
Looks like one of the parameter names is misspelled. It should be reloadOnChange=true
(singular).
NB: IIRC, application settings are only read once, when the application starts. So be sure to reload your app first, so the changes to THIS.javaSettings are detected.
来源:https://stackoverflow.com/questions/28670082/stale-java-classes-when-using-coldfusion-10s-custom-java-loader