问题描述
我试图使用ColdFusion 10的能力来加载自定义Java类并监视更改。我已经能够成功加载Java类,但是它们不会在更改和重新编译时更新。以下是使用ColdFusion 10的java加载和JavaLoader库的示例; JavaLoader库工作,ColdFusion 10不工作。
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
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
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
TestRT.java
public class TestRT {
public static String echo(String e){
return "Hiye "; //+ response;
}
}
项目结构:
>
输出:
正如你所看到的,JavaLoader库已经获取更新的hiye,但ColdFusion 10仍然使用带有hiy的旧版本。为什么ColdFusion不会改变?我有 reloadOnChanges = true,watchInterval = 5
设置
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
推荐答案
其中一个参数名称拼写错误。它应该是 reloadOnChange = true
(单数)。
Looks like one of the parameter names is misspelled. It should be reloadOnChange=true
(singular).
注意: IIRC,应用程序设置只有在应用程序启动时才会读取一次。因此,请务必先重新加载您的应用程序,因此检测到对THIS.javaSettings的更改。
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.
这篇关于使用ColdFusion 10的自定义Java加载程序时使用过时的Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!