ColdFusion:关于使用定制的“自己写的";Java 类 [英] ColdFusion: about using custom "own written" Java classes

查看:24
本文介绍了ColdFusion:关于使用定制的“自己写的";Java 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 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:

  1. 创建一个源文件即YourTestClass.java
  2. 将源代码编译成类文件即YourTestClass.class
  3. 将编译好的.class文件放在CF类路径的某处,如:

  1. Create a source file ie YourTestClass.java
  2. Compile the source code into a class file ie YourTestClass.class
  3. Place the compiled .class file somewhere within the CF classpath, such as:

  • WEB-INFclasses - 用于单个 .class 文件
  • WEB-INFlib - 用于 .jar 文件(多个类)

  • WEB-INFclasses - for individual .class files
  • WEB-INFlib - 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屋!

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