問題描述
我需要在 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
將編譯好的
.class
文件放在CF類路徑的某處,如:
- Create a source file ie
YourTestClass.java
- Compile the source code into a class file ie
YourTestClass.class
Place the compiled
.class
file somewhere within the CF classpath, such as:
WEB-INFclasses
- 用于單個.class
文件WEB-INFlib
- 用于.jar
文件(多個類)
WEB-INFclasses
- for individual.class
filesWEB-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 類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!