ColdFusion:关于使用定制的“自己写的” Java类 [英] ColdFusion: about using custom "own written" Java classes
问题描述
我需要在cfml页面中使用我自己的java类。
I need to use my own java class in a cfml page.
文档中的此条目听起来不错,但不解释我必须创建哪些文件。
This entry in the documentation sounds great but does not explain which files I have to create.
我试图在我的网站根目录下创建一个 test.cfm
页面。然后在同一路径中放置 TestClass.java
+ TestClass.class
。
I tried to create a test.cfm
page under my website root. Then placed TestClass.java
+ TestClass.class
in the same path. But that results in an error "class not found"!.
推荐答案
解决方案
在同一路径中的TestClass.java + TestClass.class。
a TestClass.java + TestClass.class in the same path.
你不能把 .class
文件放在任何地方。当CF服务器启动时,仅 检查类/ jar的特定位置。这些位置被称为CF类路径。您编译的 .class
文件必须放在CF类路径中,否则将无法检测到。
You cannot just place .class
files anywhere. When the CF server starts, it only checks specific locations for classes/jars. Those locations are referred to as the "CF class path". Your compiled .class
file must be placed within the CF class path, or it will not be detected.
使用自定义的java类:
To use a custom java class:
- 创建源文件
YourTestClass.java
- 将源代码编译为类文件
YourTestClass.class
-
在CF类路径中某处编译的
.class
文件,例如:
- code> WEB-INF \classes - 个人
.class
档案 -
WEB-INF \lib
- 用于.jar
文件(多个类)
WEB-INF\classes
- for individual.class
filesWEB-INF\lib
- for.jar
files (multiple classes)
注意:您也可以通过 ColdFusion管理员。
Note: You could also add the item to the CF class path via the ColdFusion Administrator. However, placing the class in one of the default directories is simpler.
重新启动ColdFusion服务器以检测新类
Restart the ColdFusion server so it detects the new classes
注意:尽管你可以使用单独的 .class
文件,到 .jar
文件。
Note: Though you can use individual .class
files, it is more common to package them into .jar
files.
这篇关于ColdFusion:关于使用定制的“自己写的” Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!