如何在 Coldfusion 中使用 java 文件
我需要将 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.
相关文章