Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
536 views
in Technique[技术] by (71.8m points)

class - ColdFusion: about using custom "own written" Java classes

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.

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"!.

Can you please help me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

a TestClass.java + TestClass.class in the same path.

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.

To use a custom java class:

  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 - for individual .class files
    • WEB-INFlib - for .jar files (multiple classes)

    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.

  4. Restart the ColdFusion server so it detects the new classes

Note: Though you can use individual .class files, it is more common to package them into .jar files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...