本文介绍了ColdFusion:关于使用自定义&“自己编写的& amp; amp; quot;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"!.

你能帮我吗?

推荐答案

您不能仅将 .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-INF \ classes -用于单个 .class 文件
  • WEB-INF \ lib -用于 .jar 文件(多个类)

  • WEB-INF\classes - for individual .class files
  • WEB-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:关于使用自定义&“自己编写的& amp; amp; quot;Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 22:20