Welcome!

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,
    or
    - Blackdown 1.2.2 RC 4 (or bet- ter) for the Linux platform
  • A Java servlet engine
    - JRun 3.0 (any edition),
    or
    - Apache 1.3.x Tomcat
  • An Enterprise JavaBean server
    - JRun 3.0 (Enterprise or Developer Editions),
    or
    - 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,

/usr/local/jdk1.2.2/jre/lib/i386/classic/libjvm.so

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.

JAVAPATH=/usr/local/jdk1.2.2

LD_LIBRARY_PATH=$CFHOME/lib:$JAVAPATH/jre/lib/i386/classic:$JAVAPATH/jre/
lib:$JAVAPATH/jre/lib/i386/native_threads:$JAVAPATH/jre/lib/i386

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

C:\CFusion\CFX;C:\Test

On my Linux machine,

/opt/coldfusion/cfx:/usr/local/test

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.

CFX JAR Path
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:

C:\CFUSION\Java\classes

On my Linux machine,

/opt/coldfusion/Java/classes

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
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...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
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 ...
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 ...
DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
@DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
SYS-CON Events announced today that Cedexis will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
SYS-CON Events announced today that Google Cloud has been named “Keynote Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
SYS-CON Events announced today that Opsani will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.
SYS-CON Events announced today that Nirmata will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nirmata provides a comprehensive platform, for deploying, operating, and optimizing containerized applications across clouds, powered by Kubernetes. Nirmata empowers enterprise DevOps teams by fully automating the complex operations and management of application containers and its underlying ...
SYS-CON Events announced today that Opsani to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. Opsani is creating the next generation of automated continuous deployment tools designed specifically for containers. How is continuous deployment different from continuous integration and continuous delivery? CI/CD tools provide build and test. Continuous Deployment is the means by which...