ColdFusion MX supports Java proxies to access COM objects. If you do not create Java proxies in advance, ColdFusion must dynamically discover the COM interface. This technique can have two disadvantages:
To overcome these problems, ColdFusion MX includes a utility, com2java.exe, that creates static Java stub proxy classes for COM objects. ColdFusion can use these Java stubs to access COM objects more efficiently than when it creates the proxies dynamically. Additionally, the com2java.exe utility can create stubs for features that the dynamic proxy generator might miss.
ColdFusion MX ships with pregenerated stubs for the Windows XP, Windows 2000, and Windows 97 editions of Microsoft Excel, Microsoft Word, and Microsoft Access. ColdFusion MX is configured to automatically use these stubs.
If you create Java stub files for a COM object, you continue to use the cfobject
tag with a type
attribute value of COM
, or the CreateObject
function with a first argument of COM
, and you access the object properties and methods as you normally do for COM objects in ColdFusion.
Use the following steps to use the com2java.exe utility. This procedure uses Microsoft Outlook as an example.
mkdir C:\src\outlookXP
This directory can be temporary. You add files from the directory to a ColdFusion JAR file.
Select
button.Note: Macromedia uses a package name that starts with coldfusion.runtime.com.com2java for the packages that contain the preinstalled Java stubs for Microsoft Excel, Microsoft Word, and Microsoft Access. For example, the name for the package containing the Microsoft Word XP Java stub classes is coldfusion.runtime.com.com2java.wordXP. This package name hierarchy results in the wordXP classes having a path inside the msapps.jar file of coldfusion\runtime\
com\com2java\wordXP\className.class. Although this naming convention is not necessary, consider using a similar package naming convention for clarity, if you use many COM objects.
The files generated in your directory include the following:
javac -J-mx100m -J-ms100m *.javaThe compiler switches ensure that you have enough memory to compile all the necessary files.
Note: If you did not put jintegra.jar on your CLASSPATH in step 1b, add the switch
-classpath:/
cf_root
/lib/jintegra.jar
, wherecf_root
is the directory where ColdFusion is installed, to the command.
jar -uvf cf_root\lib\msapps.jar directoryName\*.classWhere cf_root is the directory where ColdFusion MX is installed and directoryName is the name of the directory that contains the class files. For the OutlookXP example, enter the following line:
jar -uvf C:\CFusionMX7\lib\msapps.jar outlookXP\*.class
<var name="progID"> <string>PackageName.mainClass</string> </var>
Use the following values in these lines:
ProgID The COM object's ProgID, as displayed in the OLE/COM object viewer.
PackageName The package name you specified in step 3c.
mainClass The main class of the COM object. The main class contains the methods you invoke. For many Microsoft applications, this class is Application. In general, the largest class file created in step 4. is the main class.
For example, to add outlookXP to neo-comobjmap.xml, add the lines in bold text above the </struct>
end tag:
<var name="access.application.9"> <string>coldfusion.runtime.com.com2java.access2k.Application</string> </var> <var name="outlook.application.10"> <string>outlookXP.Application</string> </var> </struct>
In this example,
outlook.application.10 is the ProgID of the Outlook COM object, outlookXP is the package name you specified in step 3c, and Application is the COM object's main class.