2

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:

enter image description here

Output:

enter image description here

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

Richard Tingle
  • 16,906
  • 5
  • 52
  • 77
  • Your code looks good to me, not that it is a feature I have personally used. What version of CF10 are you running, e.g. up-to what updater do you have installed? Maybe this was a bug that has been patched. Have you checked the Adobe Bugbase? (https://bugbase.adobe.com/) – andrewdixon Feb 23 '15 at 09:31
  • @cfqueryparam that seems to be talking about the pre coldfusion 10 behaviour where using the javaloader library was the only way to deploy custom java classes on change. Cf10 is *supposed* to have this behaviour natively – Richard Tingle Feb 23 '15 at 10:31
  • @andrewdixon I'm on 10,0,15,292620 which I believe is the most up to date (of version 10). I've not found anything in the bugbase yet – Richard Tingle Feb 23 '15 at 15:07
  • This question is not a duplicate of the marked thread. [As noted above](http://stackoverflow.com/questions/28670082/stale-java-classes-when-using-coldfusion-10s-custom-java-loader#comment45636956_28670082), it refers to the JavaLoader, not the new CF10 feature. Voting to re-open. – Leigh Feb 23 '15 at 19:45

1 Answers1

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.

Leigh
  • 28,765
  • 10
  • 55
  • 103
  • *the JavaLoader library has picked up the updated "hiye"* That is because the code creates a new instance each time, meaning it reloads all classes on every request. FYI, see [Using a Java URLClassLoader in CFMX Can Cause a Memory Leak](http://www.compoundtheory.com/using-a-java-urlclassloader-in-cfmx-can-cause-a-memory-leak/) – Leigh Feb 23 '15 at 18:22
  • Ah dynamically typed languages. Thank you! – Richard Tingle Feb 23 '15 at 19:38