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
"We've been engaging with a lot of customers including Panasonic, we've been involved with Cisco and now we're working with the U.S. government - the Department of Homeland Security," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"We provide IoT solutions. We provide the most compatible solutions for many applications. Our solutions are industry agnostic and also protocol agnostic," explained Richard Han, Head of Sales and Marketing and Engineering at Systena America, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that Calligo, an innovative cloud service provider offering mid-sized companies the highest levels of data privacy and security, has been named "Bronze 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. Calligo offers unparalleled application performance guarantees, commercial flexibility and a personalised support service from its globally located cloud plat...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
"The Striim platform is a full end-to-end streaming integration and analytics platform that is middleware that covers a lot of different use cases," explained Steve Wilkes, Founder and CTO at Striim, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that DXWorldExpo has been named “Global 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. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
SYS-CON Events announced today that Datera, that offers a radically new data management architecture, has been named "Exhibitor" 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. Datera is transforming the traditional datacenter model through modern cloud simplicity. The technology industry is at another major inflection point. The rise of mobile, the Internet of Things, data storage and Big...
"We are focused on SAP running in the clouds, to make this super easy because we believe in the tremendous value of those powerful worlds - SAP and the cloud," explained Frank Stienhans, CTO of Ocean9, Inc., in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
DX World EXPO, LLC., a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
While the focus and objectives of IoT initiatives are many and diverse, they all share a few common attributes, and one of those is the network. Commonly, that network includes the Internet, over which there isn't any real control for performance and availability. Or is there? The current state of the art for Big Data analytics, as applied to network telemetry, offers new opportunities for improving and assuring operational integrity. In his session at @ThingsExpo, Jim Frey, Vice President of S...
SYS-CON Events announced today that DXWorldExpo has been named “Global 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. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
In his opening keynote at 20th Cloud Expo, Michael Maximilien, Research Scientist, Architect, and Engineer at IBM, discussed the full potential of the cloud and social data requires artificial intelligence. By mixing Cloud Foundry and the rich set of Watson services, IBM's Bluemix is the best cloud operating system for enterprises today, providing rapid development and deployment of applications that can take advantage of the rich catalog of Watson services to help drive insights from the vast t...
SYS-CON Events announced today that EnterpriseTech has been named “Media 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. EnterpriseTech is a professional resource for news and intelligence covering the migration of high-end technologies into the enterprise and business-IT industry, with a special focus on high-tech solutions in new product development, workload management, increased effic...
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, has been named "Exhibitor" 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. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze 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. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and ...
SYS-CON Events announced today that CHEETAH Training & Innovation 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. CHEETAH Training & Innovation is a cloud consulting and IT training firm specializing in improving clients cloud strategies and infrastructures for medium to large companies.
SYS-CON Events announced today that Datanami has been named “Media 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. Datanami is a communication channel dedicated to providing insight, analysis and up-to-the-minute information about emerging trends and solutions in Big Data. The publication sheds light on all cutting-edge technologies including networking, storage and applications, and thei...
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...