You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

Related Topics: ColdFusion

ColdFusion: Article

A Cold Cup o'Joe - Part 1

A Cold Cup o'Joe - Part 1

There are times during the development of a ColdFusion application when CFML is not the best tool for the job. While this might seem to be a contradiction, it's true nonetheless. Allaire recognized this and while CFML has gotten to be a pretty pumped up scripting language, sometimes it's necessary to get a little help.

That help can come in a big way from Java in the form of regular classes, applets, servlets, EJB, and CFX tags. Building these components in Java gives you access to a powerful array of language extensions that are simply not available or are impractical to implement in CFML.

In this series of articles we'll look at how Java integrates with CFML and the ColdFusion Server (specifically 4.5.1 SP2).

To utilize the information contained in this series, you'll need to have a few software packages in-stalled:

  • ColdFusion Server 4.5.1 Service Pack 2 (Professional or Enterprise editions)
  • Java 2 SDK
    - Sun's Production release 1.2.2,
    - Blackdown 1.2.2 RC 4 (or bet- ter) for the Linux platform
  • A Java servlet engine
    - JRun 3.0 (any edition),
    - Apache 1.3.x Tomcat
  • An Enterprise JavaBean server
    - JRun 3.0 (Enterprise or Developer Editions),
    - BEA WebLogic
Verifying Your ColdFusion Server Version
From within the ColdFusion Administrator navigate to the Version Info screen. The hyperlink for this screen is the last under the Server menu. The second entry under the Server Information section is Version and reflects the version of the server. It's important to be using at least version 4.5.1 SP2. While many of the samples in this series will work with 4.5, there are some quirks that can cause failure.

Obtaining a JDK
The documentation Administering ColdFusion Server, Chapter 3, "Configuring ColdFusion Server," specifies that the Java 2 virtual machine must be installed. A Java 2 platform can be obtained from either Sun's Java Web site (www.javasoft.com/j2ee/j2sdkee) or from Linux, the Blackdown site, where a listing of mirrored locations is given (www.blackdown.org/java-linux/mirrors.html).

Obtaining a Servlet Engine
Suitable Java servlet engines for this series are Allaire's JRun 3.0 and the Tomcat extension to the Apache Web server ( http://jakarta.apache.org/tomcat/index.html). The more obvious choice is the JRun product. While the Apache Tomcat extension is a fine product, JRun's integration is tighter, allowing use of the <CFSERVLET> tag, and the Developer and Enterprise editions have EJB capability.

Obtaining an EJB Server
Suitable EJB servers for this series are Allaire's JRun 3.0 and BEA System's WebLogic (www.beasys.com/). Again, while the alternatives to the Allaire product line are worthy of consideration in their own right, the better integration will come with JRun.

Series Environment
I'll be using both Windows and Linux for all the examples in this series. The Windows machine will be Windows 2000 Professional, Service Pack 1, with ColdFusion Server (Enterprise Edition) 4.5.1 SP2, IIS 5.0, Sun's J2EE JDK (1.2.2), and JRun 3.0 SP1. The Linux machine will be RedHat 6.2, with ColdFusion Server (Enterprise Edition) 4.5.1 SP2, Apache 1.3.12, Blackdown's Java 2 JDK (1.2.2 RC 4), and JRun 3.0 SP1. All deviations from this platform will be clearly noted.

My Windows installation has ColdFusion and JRun installed to their default locations: C:\CFUSION and C:\JRUN, respectively. The JDK is installed at C:\Program Files\Javasoft\JDK\1.2.2.

My Linux installation has ColdFusion and JRun installed to their default locations: /opt/coldfusion and /opt/jrun, respectively. The JDK is installed at /usr/local/jdk1.2.2.

Configuring the Administrator Java Settings Panel
Before we can do any integration with Java we need to configure the ColdFusion Server. So let's get down to business. Allaire provides us with what appears to be a fairly straightforward Settings panel for configuring Java. There are, however, some tricks to getting everything to run just right. We'll discuss some of them and how to avoid obstacles.

There are eight different settings in the Java Settings panel:

  1. Load JVM when starting Cold-Fusion checkbox
  2. JVM Path setting
  3. Class Path setting
  4. JVM Initial Heap Size setting
  5. JVM Max Heap Size setting
  6. System Options setting
  7. Implementation Options setting
  8. CFX JAR Path setting
As you can see in Figure 1, Allaire has made three default settings from which we can work. The Initial Heap Size of 1024K, the Max Heap Size of 16384K, and CFX JAR Path, which on my Windows machine is C:\CFUSION\Java\classes.

Load JVM When Starting ColdFusion
This setting indicates whether the ColdFusion Server should load the JVM when it starts. When it's un-checked, the ColdFusion server will load the JVM when the first Java object (class or EJB) or Java CFX is called. Clearly this is an issue of system performance and user perception.

If the JVM path is set incorrectly and the ColdFusion Server is flagged to load the JVM at start-up, the server will fail to start. An error message will get set in the server.log file; for example, on Windows,

"Error attempting to start the service,"

and on Linux (complete with sentence error),

"Unknown exception occurred while trying initialize the services."

This can create a tricky situation since the error doesn't inform us that the JVM failed to load. If you've adjusted a number of different settings, you don't know for certain which one is the culprit. It becomes even dicier once you decide to turn off the setting, since the ColdFusion Administrator can no longer be accessed! This setting can be adjusted through the registry at HKEY_ LOCAL_MACHINE\ SOFTWARE\Allaire\ColdFusion\ Current Version\ JVM through a string setting, JVMLoad. A value of 1 means to load on start, and a value of 0 means not to load on start (Knowledge Base Article 15018, www.allaire.com/Handlers/index.cfm?ID=15018&Method=Full). This can be done through the registry editor (Regedit. exe) on Windows or using a favored text editor on the cf.registry file in the registry subdirectory of the ColdFusion installation on UNIX. This problem is more commonly found on Windows machines, where setting the JVM Path setting is not as straightforward as it is on the UNIX platforms.

JVM Path
This setting can be tricky on Windows machines. For whatever reason, Allaire chose not to be very flexible about their path requirements. The use of forward slashes is re-quired, even on Windows (Knowledge Base Article 13863, www. allaire. com/Handlers/index.cfm?ID= 13863&Method =Full). While this isn't a problem on the UNIX platforms, failure to do so on Windows will cause the server to fail to start or hang when a Java call is made; for example, on my Windows machine,

C:/Program Files/Javasoft/JDK/1.2.2/jre/ bin/classic/ jvm.dll

or on my Linux machine,


There's an additional setting that must be made on the UNIX platforms. An alteration to the LD_ LIBRARY_PATH variable in the start script must be made to include locations to various subdirectories of the JDK installation (Knowledge Base Article 15452, www.allaire.com/Handlers/index.cfm?ID=15452&Method=Full). This will make certain that the needed shared objects get loaded with the server. The ColdFusion Server will have to be restarted for this to take effect.



Class Path
This setting defines the Java CLASSPATH used for locating CFX class files, regular class files, and EJB components. I like to set it to the CFX subdirectory of the ColdFusion Server installation. Whether it's a CFX written in Java, C++, or Delphi is immaterial to me; my logic follows that any CFX belongs in the CFX subdirectory. In addition, the path to any auxiliary classes needed should be included as well. For example, on my Windows machine it's at


On my Linux machine,


A number of bugs are documented as being corrected in Release Notes for ColdFusion Server SP1 (Knowledge Base Article 17751, www.allaire.com/Handlers/index.cfm?ID=17751&Method=Full) and SP2 (Knowledge Base Article 18364, www.allaire.com/Handlers/index.cfm?ID=18364&Method=Full). However, verifying this at the time this article was written is difficult, as two other Knowledge Base Articles (17329 and 17334) referenced in the SP1 Release Notes are inaccessible. It's hard to tell if this is a technical glitch at the site, if the articles have been removed, or if those articles were never meant for public consumption.

Reading into the Release Notes, one article seems to indicate that on UNIX the Class Path setting is lost when the server is restarted. The other seems to indicate two different problems, one on UNIX and the other on an unspecified platform, presumably both Windows and UNIX. The former refers to changing the path separator from a semicolon to a colon, and the latter to a 500-character limit in the Class Path field in the Administrator. The first two of these three bugs appear to be fixed in SP1. The 500-character limit in the Class Path is a bug for which there's an easy test. Upon closer inspection of the source of the Java Settings panel, the Class Path input field on the Windows platform is indeed set to a maximum length of 500. However, on Linux and Solaris for SP1, the maximum length is set to 250. This is corrected in SP2.

JVM Heap Size
This is a great setting for controlling the memory allocation on your server. The Initial and Maximum Heap Memory Size values allow you to adjust for your specific utilization needs. By default, the server uses 1024KB for the Initial Heap Size and 16384KB for the Maximum Heap Size. In many cases this is enough; however, Allaire recommends on Linux (Knowledge Base Article 15452, www.allaire.com/Handlers/index.cfm?ID=15452&Method=Full) 4096KB for the Initial Heap Size and 65536KB for the Maximum Heap Size. This is a good recommendation on all platforms for the kinds of things we'll be examining later in this series.

System and Implementation Options
These options show as separate entries on the Java Settings panel but I'll address them together, as they reflect the same kinds of information. Through these two settings it's possible to make configurations to the JVM. System Options are a nice keyhole into the JVM environment, allowing for global settings to be made that will affect the way the JVM runs, such as what Just-in-Time compiler to use or an alternate security manager. Entries for these settings are done in key/value pair assignment format (i.e., property=value) and separated by semicolons. For example, Java.security. manager=java.rmi.RMISecurity Manager.

Implementation Options are an-other keyhole into the JVM. Acting like command line switches, they set options for the way the JVM executes. Implementation Options are specific to a JVM implementation (for example, Microsoft's JVM might have special options for interfacing with COM services). Entries look like command line options, leading with a dash and a letter switch. You can usually get a listing of supported switches by executing your Java command with the help switch (java -h). For example, -Djava.compiler=NONE.

A problem on UNIX platforms causes these settings to clear whenever there's more than one option specified. Allaire's workaround to this is to restrict your usage of both settings to just one value each (Knowledge Base Article 15955, www.allaire.com/Handlers/index.cfm?ID=15955&Method=Full). Further complicating this is Allaire's recommendation for Linux (Knowledge Base Article 15452, www.allaire.com/Handlers/index.cfm?ID=15452&Method=Full) for the System Option setting, java. compiler =NONE.

Here the location of the Java archive containing Allaire's Java CFX library is identified. The ColdFusion Administrator provides one by de-fault. For example, on my Windows machine it's:


On my Linux machine,


Restarting the Server
Perhaps it's obvious, but I would be remiss if I left out this tidbit of information. It's necessary to restart the ColdFusion Server whenever you make a change in the settings panel if the JVM has been loaded. This can mean any time you make a change if the JVM is set to load at server start-up. At best, failing to do this can cause some confusion when templates don't act as you intend. In the case of adding to the Class Path, the ColdFusion Server will report back that it's unable to locate the referenced class or cause other classes to raise exceptions and fail. This can make for a very messy looking application.

It's possible to catch these errors programmatically with the structured exception handling in CFML (<CFTRY> and <CFCATCH>). It's a good recommendation to use try/ catch blocks liberally when working with any object. It gives you, the developer, a great deal of flexibility to enable your application to de-grade gracefully under dire situations.

Wrapping It Up
As you can see, with the exception of a few twists and turns, there really isn't much to Java enabling your ColdFusion Server installation. All that remains is to actually test the configuration. You can do this by creating a regular Java class and calling it with <CFOBJECT>. A class with a simple "hello world" functionality would do. The code for this simple test can be found in Listings 1 and 2. Compile the Java source from Listing 1, place the resulting bytecode file somewhere in your class path, and execute the template from Listing 2. I'll cover using Java classes with <CFOBJECT> in later articles, so I won't explain the listings here. To paraphrase Fermat, the explanation is too large to fit in the sidebar.

More Stories By Guy Rish

Guy Rish is a ColdFusion and .NET developer at Vente as well as President at Gestaltech. He is an active developer and writer for various languages and technologies, and has contributed work in books on ColdFusion MX, Flash MX, and Dreamweaver MX. He blogs at ccoj.coldfusionjournal.com.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

Most Recent Comments
Allan 08/20/02 08:47:00 AM EDT

I have been trying real hard to integrate JBoss with Cold Fusion. Been to many sites and have seen many queries regarding the same issue. From within CF, when an attempts is made to lookup a bean on a JBoss server, the following error is encountered:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org/jnp/interfaces/NamingContextFactory]. Java exception occurred in attempt to construct object

The classpath settings have been checked and rechecked and everything checks out.

@ThingsExpo Stories
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that Conference Guru has been named “Media Sponsor” of the 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. A valuable conference experience generates new contacts, sales leads, potential strategic partners and potential investors; helps gather competitive intelligence and even provides inspiration for new products and services. Conference Guru works with conference organizers to pass great deals to gre...
The Internet of Things will challenge the status quo of how IT and development organizations operate. Or will it? Certainly the fog layer of IoT requires special insights about data ontology, security and transactional integrity. But the developmental challenges are the same: People, Process and Platform. In his session at @ThingsExpo, Craig Sproule, CEO of Metavine, demonstrated how to move beyond today's coding paradigm and shared the must-have mindsets for removing complexity from the develop...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...