如何在 Coldfusion 中使用 java 文件 [英] How do you use java files in Coldfusion

查看:22
本文介绍了如何在 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.

这篇关于如何在 Coldfusion 中使用 java 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆