問題描述
我需要將 java 文件導入 Coldfusion 8 頁面,例如:
I need to import a java file into a coldfusion 8 page e.g. :
public class Hello
{
public String testJava()
{
return "Hello Java!!";
}
}
在 Coldfusion 中,我有以下代碼:
In Coldfusion I have the following code:
<cfscript>
helloWorld = CreateObject("java","Hello");
helloTest = helloWorld.testJava();
</cfscript>
然后我收到錯誤
對象實例化異常.找不到類:你好
Object Instantiation Exception. Class not found: Hello
在我的 Coldfusion 服務器中,Java 虛擬機路徑設置為C:/ColdFusion8/runtime/jre",所以這是我放置 java 文件的位置,對嗎?我應該在里面放一個 .java、.class 還是 .jar?
In my Coldfusion server Java Virtual Machine Path is set to 'C:/ColdFusion8/runtime/jre', So this is where I have put my java file, is this correct? Should I put a .java, .class or .jar there?
文件名需要和類名一致嗎?
Does the file name need to be consistent with class name?
有沒有人可以嘗試類似的工作示例代碼?
Does anyone have working sample code for something similar I can try?
推薦答案
您需要將文件放在 ColdFusion JVM 的類路徑中,而不是其 JRE 目錄中.
You need to put the files on the ColdFusion JVM's classpath, not in its JRE dir.
一般來說,如果你有一個jar文件,把它放在實例的WEB-INF/lib
目錄,如果它只是一個類,把它放在WEB-INF/classes
目錄,例如:對我來說后者是 C:appsadobeColdFusion11fullcfusionwwwrootWEB-INFclasses
,其中 C:appsadobeColdFusion11full
是我安裝 CF 的地方,cfusion
是實例的名稱.
As a rule, if you have a jar file, put it in the instances's WEB-INF/lib
dir, if it's just a class, put it in the WEB-INF/classes
dir, eg: for me the latter would be C:appsadobeColdFusion11fullcfusionwwwrootWEB-INFclasses
, where C:appsadobeColdFusion11full
is where I installed CF, and cfusion
is the name of the instance.
這篇關于如何在 Coldfusion 中使用 java 文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!