如何在Coldfusion8中使用javaloader设置java库?

如何在Coldfusion8中使用javaloader设置java库?,java,coldfusion,coldfusion-8,bcrypt,javaloader,Java,Coldfusion,Coldfusion 8,Bcrypt,Javaloader,我正在尝试让javaLoader在Coldfusion8应用程序中运行,我需要一些帮助来帮助我完成任务 这就是我到目前为止所做的: 内部应用程序。cfc: ... THIS.mappings["/javaloader"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "tools/javaloader"; ... <cffunction name="onApplicationStart" returnType="boo

我正在尝试让javaLoader在Coldfusion8应用程序中运行,我需要一些帮助来帮助我完成任务

这就是我到目前为止所做的:

内部应用程序。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>
<!--- create mapping to javaloder --->
<cfscript>        
    THIS.mappings["/javaloader"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "tools/javaloader";
</cfscript>

<!--- Application start --->
<cffunction name="onApplicationStart" returnType="boolean" output="false" hint="">
    <cfscript>       
        <!--- store a UUID and emptry path array in Application scope --->
        Application.str = structNew(); 
        Application.str.myJavaLoaderKey = "your_uuid_javaloader";
        Application.str.jarPaths = arrayNew(1);
    </cfscript>
     <!--- check if exists --->
    <cfif ( NOT structKeyExists(server, Application.str.myJavaLoaderKey) )>

         <!--- put all paths to your .java files here, this is for JBCrypt --->
         <cfset Application.str.jarPaths[1] = expandPath("/classes/jBCrypt-0.3")>
         <cfif ( NOT structKeyExists(server, Application.str.myJavaLoaderKey) )>

            <cflock name="#Hash(Application.str.myJavaLoaderKey)#" type="exclusive" timeout="10">
                <!--- create javaloader object and init with all submitted paths --->
                <cfset server[Application.str.myJavaLoaderKey] = createObject("component", "javaloader.JavaLoader").init(sourceDirectories=Application.str.jarPaths )>
            </cflock>
        </cfif>
    </cfif>
</cffunction>
。。。
THIS.mappings[“/javaloader”]=GetDirectoryFromPath(GetCurrentTemplatePath())和“tools/javaloader”;
... 
Application.str=structNew();
Application.str.myJavaLoaderKey=“someUUID\u javaloader”;
Application.str.jarpath=arrayNew(1);
这是按照和的说明进行的

在我的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>                             

pass=“some\u password”;
cryptonite=server[Application.str.myJavaLoaderKey];
bCrypt=cryptonite.init(Application.str.jarPaths[1]);
hashed=bCrypt.hashpw(pass,bCrypt.gensalt());
我完全可以转储cryptonite变量,但是当我尝试创建BCrypt实例时,脚本失败了

问题
我很高兴我走到了这一步,但我已经坐在上面几个小时了,不知道我做错了什么。希望有更具洞察力的人能为我指明方向


谢谢你的帮助

好的。有几个错误

要使用Coldfusion8和BCrypt或您选择的Java类设置Javaloader,请执行以下操作:

1) 将任何Java类(即.Java文件,而不是.class文件)放在webroot/htdocs(Apache)的文件夹中。我的BCrypt路径如下所示:

  htdocs/classes/jBCrypt/
  htdocs/tools/javaloader/
2) 对javaloader执行同样的操作。我的路径如下所示:

  htdocs/classes/jBCrypt/
  htdocs/tools/javaloader/
3) 在应用程序中.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>
<!--- create mapping to javaloder --->
<cfscript>        
    THIS.mappings["/javaloader"] = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "tools/javaloader";
</cfscript>

<!--- Application start --->
<cffunction name="onApplicationStart" returnType="boolean" output="false" hint="">
    <cfscript>       
        <!--- store a UUID and emptry path array in Application scope --->
        Application.str = structNew(); 
        Application.str.myJavaLoaderKey = "your_uuid_javaloader";
        Application.str.jarPaths = arrayNew(1);
    </cfscript>
     <!--- check if exists --->
    <cfif ( NOT structKeyExists(server, Application.str.myJavaLoaderKey) )>

         <!--- put all paths to your .java files here, this is for JBCrypt --->
         <cfset Application.str.jarPaths[1] = expandPath("/classes/jBCrypt-0.3")>
         <cfif ( NOT structKeyExists(server, Application.str.myJavaLoaderKey) )>

            <cflock name="#Hash(Application.str.myJavaLoaderKey)#" type="exclusive" timeout="10">
                <!--- create javaloader object and init with all submitted paths --->
                <cfset server[Application.str.myJavaLoaderKey] = createObject("component", "javaloader.JavaLoader").init(sourceDirectories=Application.str.jarPaths )>
            </cflock>
        </cfif>
    </cfif>
</cffunction>

THIS.mappings[“/javaloader”]=GetDirectoryFromPath(GetCurrentTemplatePath())和“tools/javaloader”;
Application.str=structNew();
Application.str.myJavaLoaderKey=“您的\u uuid\u javaloader”;
Application.str.jarpath=arrayNew(1);
根据,设置应在应用范围内。这将设置您现在可以从其他地方引用的所有.java类,如:

<cfscript>
    var pass = "a_password";
    javaLoader = server[Application.str.myJavaLoaderKey];
    // create an instance of javaloader-BCrypt
    bcrypt = javaLoader.create("BCrypt").init();
    // now you can call methods from bcrypt like so:
    hashed = bcrypt.hashpw(pass, bcrypt.gensalt());
</cfscript>

var pass=“a_密码”;
javaLoader=server[Application.str.myJavaLoaderKey];
//创建javaloader BCrypt的实例
bcrypt=javaLoader.create(“bcrypt”).init();
//现在您可以从bcrypt调用方法,如下所示:
hashed=bcrypt.hashpw(pass,bcrypt.gensalt());
通读一遍就明白了。事实证明,您必须引用.java文件,而不是.class文件,我最初是这样做的

以下链接也可能有帮助:



。。或者您可以将
*.class
文件放入
*.jar
中,然后像往常一样加载jar。尽管动态编译
*.java
文件的能力确实是一个很好的特性:)我想我需要的不仅仅是coldfusion中的一条白带。。。下次我会试试的,很高兴你解决了。但下一次,“脚本失败”是不明确的:)它是如何失败的:空白页,错误。。。?始终包含完整的错误消息(在使用java对象时,还应包含完整的
堆栈跟踪
)。