Installing and Using Java Objeds ColdFusion Help

Using the CFOB)ECTtag or the CreateObj ect function you can load arid use Java classes or Enterprise Java Beans in your ColdFusion templates. To do so, you first need to specify. your Java class path using the ColdFusion Administrator. Your Java class path, which points to all directories containing Java class and the Java Beans that you want use in ColdFusion, should be specified in the Class Path field of the Java page of the ColdFusion Administrator as outlined in Chapter 35, “ColdFusion Administration.” The path should be a series. of directories separated by semi-colons .

Once the path is in place you can place any Java Beans or classes you need to use in ColdFusion in one of the directories on the path you specified in order to be able to access them from your templates

Using Java Objects with ColdFusion

Before you can start using a Java class or Bean in ColdFusion you must create a reference to the object. This is done with the CFOBJECTtag. All you need to know about the object at this point is the name of class or the Java Bean. For instance if you have a class named MyClass on the class path you specified in the ColdFusion Administrator you can create a reference to the class with the CFOBJECTtag

Executing External Applications

Starting with ColdFusion 4.5 you can execute any process on the server machine in the same way that you can by issuing a command at the command prompt. To do this you use the CFEXECUTE tag

The CFEXECUTEtag takes the following basic form

CFEXECUTE NAME-‘<program to execute>’
ARGUMENTS='<command arguments>’
OUTPUTFILE-‘<output fi7e>’
TIMEOUT-‘<timeout in seconds>’)-

The NAME parameter is’required. You need to specify the complete path to the command you want to execute including any extensions such as . exe in Windows. The remaining parameters that follow are optional

• ARGUMENTS: Specifies the arguments to pass to the command.
• OUTPUTFILE: Indicates the file where any output from the command should be stored. If you do not specify a file, any output will be included in the page.generated by your ColdFusion template.
• TIMEOUT: Indicates in seconds how long Cold Fusion will wait for the process to generate output. If you specify a value of 0, your template will invoke the specified command and then not wait for output but proceed to execute the rest of the template. If you are not redirecting output to a file and you do not specify a timeout then output’ will not be available in your template

By way of example if you want to include the Ethernet statistics output of the netstat command in Windows NT in your template, you would need to include the following tag block:

<CF~XECUTE NAME-‘C:\WinNT\System32\netstat.exe’
ARGUMENTS=’-e’
TIMEOUT-‘ l’>
</CFEXECUTE>

Because the nets tat . exe-e command returns output quite quickly a timeout of one second is generally sufficient

Where Do We Go from Here?

Now that you’ve got a basic understanding of how COM objects can be used in ColdFusion, you may want to see what pre-built components ar~ out there. The Web sites listed earlier in the chapter are good places to start. In addition to component listings, these sites will provide links to other related repositories. Pick a component that you like and try it out. Maybe you’ll want to write your own CFML custom tag to encapsulate the COM object’s functionality in a more familiar tag-based syntax for other developers. If you’re a VB programmer ColdFusion’s COM support provides an easy way to extend ColdFusion’s functionality with your own custom components

In the next chapter you’ll examine Web Distributed Data Exchange (WDDX)an exciting new technology introduced with Coldfusion 4 that has the potential to revolutionize the way that Web sites interact with one another as well as to enhance the user’s experience with your application

Posted on November 16, 2015 in Including External Object

Share the Story

Back to Top
Share This