|
|
YOUR FEEDBACK
SOA World Conference
Virtualization Conference $200 Savings Expire May 16, 2008... – Register Today! Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP COLDFUSION LINKS CF Techniques
CFML on J2EE: Easy as 1-2-3
Don't give up on your CFML apps!
By: Charlie Arehart
Digg This!
Why reinvent the wheel when you can easily run your CFML applications on any J2EE server? If your team is considering or being forced to move to J2EE (WebLogic, WebSphere, JBoss, Tomcat, etc.), it may be helpful to know that you don't have to throw away or even rewrite your CFML applications. Some people may want you to rewrite them, and as a long-term goal it may make sense in some cases, but did you know that CFML can run, as-is, on the J2EE server? It really can be as easy as 1-2-3. If you've not seen it done, or you're skeptical - and especially if you've tried it with CFMX - I'll show you an alternative that you may not have seen before. Why CFML on J2EE? Even for Skeptics If you're a J2EE developer or administrator who's been handed this article by a CFML fan hoping to keep his apps alive while following your architectural and software engineering direction, I, too, hope to persuade you. I appreciate that J2EE folks may have strong objections to considering the notion. You may not see a place for CFML in your organization. But if the CFML is packaged as a standard J2EE Web app, do you really need to debate semantics? This solution allows you to work together to decide when (or if) to rewrite the CFML as a JSP/servlet application - while reaping all the benefits (for both J2EE and CFML folks) of running the CFML as a standard J2EE Web app until then. In this article I want to demonstrate just how easy this can be. Whether you're an old hand at deploying J2EE Web apps, or have still not even installed a J2EE server, or perhaps don't even know what a J2EE server is, I'll show you how you can go from having a CFML application to having it run on a J2EE server in three quick, easy steps. It can literally be just a matter of drag, drop, and deploy. BlueDragon/J2EE: A New Alternative Here, instead, I'd like to show you an alternative, and one that may be new not only to J2EE folks who think ColdFusion is the only way to run CFML, but even to many CFML developers. More important to this article and to those deploying on J2EE, it's easier and more standard as a means to deploy CFML as a J2EE Web app. BlueDragon, from New Atlanta, has become more and more familiar to many in the CF community. Just as J2EE developers can choose from many J2EE servers, now CFML developers can choose from more than just Macromedia ColdFusion MX as a solution to run their CFML. It's not a repackaging of ColdFusion (more a reverse-engineering effort), but the point is that your CFML simply runs on this alternative engine, which in the case of BlueDragon/J2EE means that your CFML runs as a J2EE Web app. No ColdFusion is required (and indeed no BlueDragon server is required, as it's just a J2EE Web app). If you can hold your skepticism at bay, and wait a few moments for answers to your questions (price, performance, compatibility, legitimacy, etc.), I'd like to start by simply showing you the three-step deployment process. Folks who've tried to deploy on, say, WebLogic, WebSphere, or Tomcat using ColdFusion have always been very surprised at how easy this alternative is. Download Free Trial/Developer Edition To check out the J2EE deployment solution, visit the downloads page (www.newatlanta.com/c/products/bluedragon/download/home). There are four editions of BlueDragon (two stand-alone server editions and the upcoming .NET edition, in addition to the J2EE edition). You'll want the J2EE edition for this article. (If you're interested in .NET instead, the .NET edition will allow you to deploy CFML on .NET. We make CFML the only language to deploy on both J2EE and .NET! More on that in an upcoming article.) All editions are available free for trial and development. In the case of the J2EE edition, it comes first as a single-IP developer edition with no expiration date. Feel free to use it against any J2EE server you have and have your developers get started with seeing how easy deploying CFML on J2EE can be. (I say "any" because all of the major J2EE servers are supported, and BlueDragon has worked with every server tested so far. See the New Atlanta Web site and/or documentation for a current list of tested servers.) You can arrange to receive a 30-day trial license key with no IP limitations. And after the trial (or if you don't bother to get the trial license), you can continue to use the developer edition to test/create code for exploration or for deployment for production with a production license key. No Installer. No Wizard. No Server. Just Zips and WARs Just extract this Zip file to your workstation or server into the directory of your choice, as shown in Figure 1, where I've named it BlueDragon_J2EE. This isn't where the code will run. In fact, J2EE servers have a notion of deploying Web applications onto the server, so this directory will serve more as a starting point from which you'll begin the drag-and-drop process. Notice that the directory contains mostly documentation in the form of PDFs and a couple of .txt files. Check those out after reading this article to learn more. The only two things other than docs are in fact the real meat of the BlueDragon/J2EE deployment process. First is an available BlueDragon61.war file. Second is a BlueDragon_webapp_61 directory. You can use the first as a quick demo and the second as a model Web application with which you can deploy your own CFML application. Those who've tried to deploy on J2EE using CFMX will be surprised to see that the BlueDragon Web apps have a much smaller footprint than CFMX's version: about 10MB versus 70-110MB for CFMX. For newcomers to J2EE, Web applications (typically JSPs and servlets) are packaged into a directory structure with certain key characteristics, notably a WEB-INF subdirectory and a web.xml file. Each of those exists in the BlueDragon_webapp_61 directory, and in the BlueDragon61.war file, which is really nothing more than a Zipped version of that directory structure, renamed as a WAR file. Deploying BlueDragon/J2EE on Your J2EE Server For a moment, let's not even worry about deploying your particular CFML application. The BlueDragon Web app as downloaded from New Atlanta has in it a sample index.cfm file that just does some basic things like calling a custom tag (as well as Java and C++ CFX custom tags) and doing a CFDUMP. It can be used to determine if indeed the app, once deployed, is allowing CFML to run. Later I'll show you how to deploy your own CFML just as easily. For now you can just take the WAR file (BlueDragon61.war) and either deploy it yourself (if you're running the J2EE server yourself) or give it to your J2EE administrator to deploy (e-mail it, FTP it, copy/paste it to a directory). Again, it's just a J2EE Web app. If you're not familiar with the concept of deployment, I'll explain that momentarily. For those familiar with the concept, let me just say that the fact that the Web app's got a CFML page in it (and soon, your entire application), along with some files that run the CFML, should be immaterial and transparent to the J2EE folks. It could just as well contain the JSPs and servlets they'd normally expect; indeed, there's a sample JSP in there as well. You may know that once the Web application is deployed, the J2EE server will know what to do with the JSP page. With BlueDragon, the entries in the web.xml file and other files in various subdirectories of the Web app will enable the CFML to run on the J2EE server. The Concept of Deployment in J2EE With J2EE servers, things work differently. Actually, there are a few ways they can work, depending on whether you're using an external Web server like IIS or Apache or are just leveraging whatever built-in Web server exists in the J2EE server, and whether you're using EAR (enterprise archive) files or WAR (Web application archive) files. The concept of deployment of a Web application can be nearly as simple as dropping a Web application directory into a particular place, but it generally involves extra steps taken by the app server under the covers. In the end, though, you still end up with your Web application ready to be called from a browser, perhaps using a particular port or context path, which is similar to a Web server mapping. But what, then, does it mean to deploy a Web app on a J2EE server? In some cases, it's really no different than dropping the application into a particular directory on the J2EE server, which automatically deploys the code for you. In other cases, you may need to use an administrative console to deploy the app. The actual steps vary. Some J2EE servers permit you to drop a Web app into a particular directory to auto-deploy it, or they may allow it only if the J2EE server has been set up in development mode. Servers permitting such drag-and-drop deployment include WebLogic, JRun, Tomcat, and ServletExec. Some servers (like JBoss) will let you drop the Web app into a particular location to auto-deploy, but it must be a WAR file (or, curiously, a Web application directory named with a .war extension). Each of these has an admin console that can be used as well. WebSphere, prior to 5.1, on the other hand, can deploy a Web application only by use of its admin console. Fortunately, you can find a discussion of the vagaries of most common J2EE servers in the appendix of the BlueDragon document, "Deploying CFML on J2EE Application Servers." Deploying the Sample WAR File For WebLogic, let's assume that you have it installed on a Windows machine in the BEA directory. If you've left it configured in its most basic way, there will be a directory such as C:\bea\user_projects\domains\mydomain\applications\ where Web apps can be deployed. This is depicted in Figure 2. You can simply drop the BlueDragon61.war example Web application into this applications directory. After doing so, and waiting a few moments (depending on the speed of your system and other activity in the server), you should be able to browse its sample index.cfm file using whatever port you use for WebLogic, using the name of the WAR file as the context path. So if you browse this WebLogic server as port 7001, and you dropped the file as named above, you could browse the index file as: http://localhost:7001/BlueDragon61/index.cfm That's it. The sample CFM file is now running on WebLogic. Of course, this is just the sample WAR file. In the next section I will show you how to deploy your own CFML. Also, you may wonder if you can have a context path other than BlueDragon61. You certainly can. Just rename the WAR file before dropping it into the applications directory. The same approach applies to JRun and Tomcat (among other servers). You just need to know where to drop the WAR file or Web app. In JRun, assuming you've installed it in C:\JRun4, and have configured the default server, you drop it into C:\JRun4\servers\default\. In Tomcat, assuming you've installed it in C:\Program Files\Apache Group\Tomcat 4.1\, you'd drop it into C:\Program Files\Apache Group\Tomcat 4.1\webapps\. It's really that easy! Try it on your J2EE server of choice. Heck, try it on more than one. The same Web app can be deployed unchanged on each of these servers. This is another powerful benefit of the BlueDragon approach. Note, again, that in WebSphere prior to 5.1(or optionally in these other servers), you can use the admin console to deploy the Web application, as demonstrated in that appendix of the BlueDragon manual, "Deploying CFML on J2EE Application Servers." Changing the Context Path In the case of WebLogic, for instance, you'd need to create (or edit) a weblogic.xml file in the WEB-INF directory of the Web application, placing in it the following lines: <weblogic-web-app> Notice that this is setting the context path to "/". Just be sure not to choose a path that would conflict with any other Web application you've deployed. In JRun, you would instead edit jrun-web.xml in the WEB-INF directory of the Web application, using a similar entry: <jrun-web-app> In the case of Tomcat, you would make a change to the single conf/server.xml file for the entire server (under the Tomcat install directory), and create a <context> entry naming the desired path and pointing to the deployed Web app. So assuming we deployed the BlueDragon61.war file, but we want to access it as "/" instead of BlueDragon61, we would use this entry: <Context path="" docBase="bd61test"/> For information on setting the context path in another J2EE server, see the appropriate documentation for that server. Deploying Your CFML Application Indeed, one of the simplest ways to demonstrate deployment onto CFML is to just copy your CFML from where you have it deployed now (perhaps the docroot of your development Web server) and paste it into the root of that BlueDragon_webapp_61 Web application directory. Since you may want to do this often, you should duplicate the BlueDragon_webapp_61 directory in place (rename it to something preferable as a context path once deployed) and then simply copy your CFML into it. Deploying the CF Example Apps So let's duplicate the BlueDragon_webapp_61 directory (as discussed above) and then rename it to bddemo. You can call it anything you like. Its contents would look like Figure 3 Notice that it has a WEB-INF directory, which contains the elements needed to run your CFML, as well as a sample index.cfm and index.jsp. The BlueDragon directory is there in support of the BlueDragon admin console (offered in the Web app by default, but removable if you don't want it there). Let's create a cfdocs directory there (since the code expects to be found in one), and then copy the exampleapps directory (since we don't need all the other directories under the original cfdocs) into that directory. I found my copy installed at C:\Inetpub\wwwroot\cfdocs\exampleapps\. Again, even if you don't have this particular code, use whatever code you have and copy it into the duplicated, renamed BlueDragon webapp directory (see Figure 4). That's really all there is to it. We can now deploy this Web application (the parent directory, now called bddemo) by simply copying and pasting it into the appropriate directory for the J2EE server, just as we did the WAR file. For instance, if I copy this "bddemo" directory into my C:\bea\user_projects\domains\mydomain\applications\ directory, then after a moment I could browse the example applications on my machine at: http://localhost:7001/bddemo/cfdocs/exampleapps/index.cfm See the sidebar "Changing the Content Path" for information on deploying the Web app to run at the root of the app server Dealing with CFML Incompatibilities The good news is that you can easily change the code in that file to work on BlueDragon by removing the reference to that particular object. It's only trying to decide whether or not the sample database, ExampleApps, is a Microsoft Access database. You can replace it with the following code snippet (save a copy of the original if you'd like): <cfscript> You may encounter other CFML incompatibilities when you deploy your own code on BlueDragon. It's often a 100% plug-compatible replacement, though some minor adjustments may be needed. If you need the benefits it offers (including easier, more standard deployment on J2EE), then dealing with modest compatibility challenges can be a small price to pay. See the blog entry, bluedragon.blog-city.com/read/601768.htm, for more information on compatibility concerns and the distinct benefits of deploying CFML with BlueDragon. There are just a few tags and functions that BlueDragon doesn't support. Then too, if you have a CF4 or 5 app, you would experience challenges in moving to CFMX as well. Many of the same tags that became obsolete or were deprecated in CFMX are also obsolete or deprecated in BlueDragon. See the BlueDragon manual CFML Compatibility Guide for more information. One other concern in deploying CFML on J2EE is a possible need to change code due to the context path. If your code was designed to run at the root of the Web server, again, you may need to change the Web application context root to "/" (as discussed earlier), or to change the code to be more flexible about its location. There's also the potential concern that some J2EE servers will copy and run the code from a different location than where you place the code for deployment (depending on the app server and how you deploy). BlueDragon comes with some extended tags and functions to help with this challenge, as discussed in the BlueDragon manual Deploying CFML on J2EE Application Servers. Changing CFML Once It's Deployed Just as you're used to with CFMX (or BlueDragon) stand-alone server editions, you can still edit CFML once it's deployed on J2EE. Save the changes, refresh the page, and you'll see that the page is reloaded immediately (and many find faster than on CFMX, though of course many factors in a given template and your configuration can influence performance). Your J2EE administrators may object to your editing the files in the deployed Web application. To J2EE purists, a deployed Web app should never be changed. Instead, you should create (or edit) the Web application outside the server (in your development environment, for instance) and then re-deploy it. This may involve stopping the Web application using the server's admin console, copying the newly updated Web app as you did before, and then redeploying it using the admin console's appropriate options. Configuring BlueDragon Administrative Settings BlueDragon Admin Console http://localhost:7001/bddemo/bluedragon/admin.cfm As in CF, this will prompt you for an admin password. Just as there is no license key by default (and it's limited to a single IP address until you arrange for a license key), so too is there no admin password defined by default (since the BlueDragon/J2EE Zip file is static, any value we might preload would be no better than loading none at all). When the admin console loads (see Figure 5), you'll see that it's very similar to ColdFusion's. You can change the admin password in General>license & security, and you can turn on debugging for each page (as in CF) using Debugging>settings. To add a data source, follow the instructions in Data & Search>data sources. Most of the options will be familiar to CF developers and administrators, and there is online help on most pages. Some J2EE administrators will balk (again) at the notion of making changes in such an admin console, preferring that the Web application not be changed once it's been deployed. We appreciate their concern. I mentioned that you can remove the admin console from the BlueDragon Web app before (or even after) deployment. Just remove the BlueDragon directory, as discussed earlier. You also need to remove the admin.bda file from the WEB-INF/bluedragon/ directory (within the Web application). Bluedragon.xml File Note that editing the bluedragon.xml or using the admin console is also the way to get the license key implemented once you obtain one. See the option General>license & security in the BlueDragon Admin console. Once you've made these changes, you can now deploy the Web application as discussed above. Admin Console "Build War File" Option J2EE Data Sources J2EE Sessions Closing Thoughts
And, as I discussed in my previous article, you can also use the Web app to deploy multiple times on a given J2EE server, such as in a clustered environment, or just to create different Web apps in the same virtual server, where they can coexist with others without conflict. J2EE Alternatives If you're in a larger organization, you'd probably lean toward IBM's WebSphere or BEA's WebLogic. If you're an Oracle shop, you'd probably choose Oracle's J2EE server. If you're fans of open source, you'd probably choose Sun ONE, JBoss, or Tomcat, to name a few. If you're a value-driven firm, you may choose Macromedia's JRun, New Atlanta's ServletExec, or any number of other alternatives. The thing is, folks in the J2EE community have long been open to considering any of several options depending on their size, their needs, their preferences, etc. Still, they knew that any of these servers could do the most basic things they needed, running their JSPs and servlets - which are just the Java way of developing Web applications. As I discussed in my previous article, there's not much JSPs and servlets can do that CFML can't. It's just that they suit Java developers very well, since they're written in Java. JSPs and servlets were once the sole province of servlet engines (Tomcat and ServletExec are servlet engines), but the J2EE specification and J2EE servers (such as WebLogic, WebSphere, and the like) evolved to do much more (running EJBs, supporting Java Messaging, and many other things). Java developers (and managers) know that whatever server or servlet engine they choose, their JSPs and servlets will run on it. They can pick and choose, even develop on one server and deploy onto another. The Sun J2EE specification clarifies what JSPs and servlets, and their packaging as J2EE Web applications, should look like. It would be helpful if the CFML community also could leverage a documented specification of what CFML should do. New Atlanta would support such an effort. If a savvy J2EE administrator wonders whether the 10MB per Web app can be reduced when multiple copies are deployed - by moving some of the WEB-INF files to a directory shared by all Web apps - the answer is yes. As I alluded to before, it's natural for J2EE administrators, along with CFML developers and their managers, to be skeptical. They've not heard of BlueDragon, and they may have an even greater aversion to CFML in general. Some other common concerns folks will have are such things as price, performance, legitimacy, etc. Let's address a couple of these quickly. As for price, the developer and trial editions of BlueDragon/J2EE are free. A commercial license lists for $2,499/CPU, with unit prices going down with multiple CPUs, multiple servers, etc. That's less than half the retail price of CFMX Enterprise, which is the edition required to deploy onto J2EE using CFMX. A license is required for any servers on which the BlueDragon Web application (and your CFML) is deployed (other than for trial or development). As for performance, New Atlanta has not yet published comparisons with CFMX. Customers have reported instances of applications that performed worse when moved from CF 5 to CFMX 6.1 but that performed better on BlueDragon. Still, you may find an instance where an app's performance is less than expected. There are just too many variables that can influence performance to be able to state any conclusive comparisons. New Atlanta is, however, committed to solving any performance problems that can be identified. As for legitimacy, it's worth noting that while New Atlanta may seem new to many CFML developers, BlueDragon has been out for a couple of years. And New Atlanta has not only been in business since 1997 (with 11,000 customers in 70 countries) but they have established a reputation for engineering expertise and quality support with their server-side Java tools, JTurbo and ServletExec. The former is a SQL Server driver (offered free within BlueDragon) and the latter is a servlet engine that's embedded within the Server/Server JX editions of BlueDragon (the way JRun underlies CFMX). It's worth noting that if you have not yet chosen a J2EE server, you can get several benefits from considering ServletExec as the server on which to deploy BlueDragon/J2EE. It, too, is available in free trial/developer editions, is priced much lower than most commercial J2EE servers, and comes with all the support New Atlanta has become known for. But the cool thing about BlueDragon/J2EE is that it works with whatever J2EE server/servlet engine you have. More important, it makes your CFML run on such servers. If you're facing the prospect of having to rewrite/port hundreds or thousands of CFML templates to J2EE, BlueDragon/J2EE may be a very cost-effective solution that protects your investment in CFML and CFML developers. CFDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||