我想讓javaLoader在Coldfusion8應用程序中運行,我需要一些幫助才能讓我穿越終點線。如何在Coldfusion8中使用javaloader設置java庫?
這是我到目前爲止有:
內的Application.cfc:
...
THIS.mappings["/javaloader"] = GetDirectoryFromPath(GetCurrentTemplatePath()) & "tools/javaloader";
...
<cffunction name="onApplicationStart" returnType="boolean" output="false" hint="application initalizer">
<cfscript>
Application.str = structNew();
Application.str.myJavaLoaderKey = "someUUID_javaloader";
Application.str.jarPaths = arrayNew(1);
</cfscript>
<cfif (NOT structKeyExists(server, Application.str.myJavaLoaderKey))>
<!--- add path to class files to jarPath Array --->
<cfset Application.str.jarPaths[1] = expandPath("/classes/BCrypt.class")>
<!--- this will map out to: ...htdocs/classes/BCrypt.class --->
<cfif (NOT structKeyExists(server, Application.str.myJavaLoaderKey))>
<cflock name="#Hash(Application.str.myJavaLoaderKey)#" type="exclusive" timeout="10">
<cfset server[Application.str.myJavaLoaderKey] = createObject("component", "javaloader.JavaLoader")>
<!--- tried .init(Application.str.jarPaths) here, but didn't do anything --->
</cflock>
</cfif>
</cfif>
<cfreturn true />
</cffunction>
在我handler.cfc,我試圖訪問javaloader和BCrypt類,像這樣:
<cfsript>
pass = "some_password";
<!--- this is accessible --->
cryptonite = server[Application.str.myJavaLoaderKey];
<!--- now trying to call init() with respective path to create an instance --->
<!--- BREAKS HERE --->
bCrypt = cryptonite.init(Application.str.jarPaths[1]);
hashed = bCrypt.hashpw(pass, bcrypt.gensalt());
</cfscript>
我可以轉儲cryptonite變量好吧,但是當我嘗試創建的實例BCrypt,腳本失敗。
問題:
我很高興我做到了這一步,但我一直沒有什麼線索,我做錯了,現在坐在這幾個小時。希望有更多見解的人可以將我指向一個方向?
感謝您的幫助!
很高興你解決它。但下一次,「腳本失敗」是模棱兩可的:)它是如何失敗的:空白頁面,錯誤,...?總是包含完整的錯誤信息(並且在使用java對象時,也包括完整的'stack trace')。 – Leigh