Dead Simple CFML Dev Environments with CFENV

Dead Simple CFML Dev Environments with CFENV

UPDATE!! 11/06/2013 Read First. 
I just updated this article to reflect some of the 
latest changes made to cfenv. 
Please refer to the README at 
<https://github.com/joshuairl/cfenv> for more complete information.
 If you have ever worked with Ruby on Rails, you know just now simple it is to spin up a new application and server to start developing. Well, due to CFML being Java based... it has loads more to do to startup and handle on the server-side. 

Some History

For awhile, I’ve been working with Railo as my development environment on my Mac. More specifically, Railo Express with Jetty and utilizing the “railo_runner” technique described on Mark Drew’s blog. If you are not familiar with that technique, it’s KIND OF similar to Rails in the sense that you can

mkdir ~/Projects/my_new_project in Terminal, then cd ~/Projects/my_new_project, and then railo_runner and it will place a WEB-INF directory and startup Jetty with Railo Express pointing to that directory. It’s creating a new WEB CONTEXT for this particular directory. It’s beautiful. You do not have to create manual entries in server.xml of Tomcat, or host your code within the webapps directory. It’s nice as is. But I wanted to make it a little better… That’s where railoenv comes in.

What is cfenv?

The railo_runner technique is awesome. But it does require some configuration initially which can get in the way of developing CFML if you’re on a new computer somewhere without Railo. I’ve decided to automate the download/install/configuration of Railo Express & railo_runner into one package and I’m calling it cfenv. The END goal is for this to be very similar in logic to rbenv and nodenv respectively.

Will it conflict with my Adobe ColdFusion and/or prior Railo installations and setups?

No, it won’t. cfenv is self contained and downloads it’s own copy of Railo Express with Jetty and maintains it for you.

How to use cfenv?

First, install cfenv. To do so, follow the instructions found at: https://github.com/joshuairl/cfenv#installation Once you’ve installed it, you will need to use cfenv to install a version of Railo.

$ cfenv install 4.1.1.009

  (which at this time is the latest version) Now we want to set this version to be used in all shells globally.

$ cfenv global 4.1.1.009

To test, create a new directory in your Sites / Projects directory… Mine are found in ~/Projects so that’s what I’ll use in my example.

$ mkdir -p ~/Projects/my_cfml_project 

And change into that directory…

$ cd ~/Projects/my_cfml_project

Now, we initialize a new railo context within the directory…

$ railo_init

You should now see output similar to the following…

mccme-rountrjf:my_cfml_project joshua$ railo_init
WARNING: System properties and/or JVM args set.  Consider using --dry-run or --exec
[ShutdownMonitor] STOP.PORT=8887
[ShutdownMonitor] STOP.KEY=railo
[ShutdownMonitor] ServerSocket[addr=/127.0.0.1,port=0,localport=8887]
Starting ShutdownMonitorThread
railo-server-root:/opt/railo/lib/ext/railo-server
Fri Nov 01 12:28:58 EDT 2013 Load Build in Core
===================================================================
SERVER CONTEXT
-------------------------------------------------------------------
- config:/opt/railo/lib/ext/railo-server/context
- loader-version:4.2
===================================================================

Fri Nov 01 12:28:58 EDT 2013-807 using JRE Date Library
Fri Nov 01 12:28:58 EDT 2013-831 write file:/opt/railo/lib/ext/railo-server/context/railo-server.xml
Fri Nov 01 12:28:59 EDT 2013-514 write file:/opt/railo/lib/ext/railo-server/context/library/tag/Dump.cfc
Fri Nov 01 12:28:59 EDT 2013-514 write file:/opt/railo/lib/ext/railo-server/context/library/tag/MediaPlayer.cfc

...

===================================================================

WEB CONTEXT (26e8ec2748b7d9a30de915bf6b5d1e3f)
-------------------------------------------------------------------
- config:/Users/joshua/Projects/my_cfml_project/WEB-INF/railo
- webroot:/Users/joshua/Projects/my_cfml_project
- hash:26e8ec2748b7d9a30de915bf6b5d1e3f
- label:26e8ec2748b7d9a30de915bf6b5d1e3f
===================================================================
Fri Nov 01 12:29:00 EDT 2013-5 write file:/Users/joshua/Projects/my_cfml_project/WEB-INF/railo/railo-web.xml.cfm
Fri Nov 01 12:29:00 EDT 2013-12 write file:/Users/joshua/Projects/my_cfml_project/WEB-INF/railo/locales/pt-PT-date.df
Fri Nov 01 12:29:00 EDT 2013-13 write file:/Users/joshua/Projects/my_cfml_project/WEB-INF/railo/video/video.xml

...

Your new web context is now running at http://localhost:8888/

Let’s create a test file for our context to load. Open up your favorite CFML Editor and add the

my_cfml_project directory to it as a new project.

Create a new file called index.cfm

Add something along these lines to the file for kicks…

<cfscript>
writeOutput('Hello, from your new cfenv context!!!'); 
writeDump(SERVER); 
</cfscript>   

Save it, and refresh http://localhost:8888/ and you should see something beautiful. :D Let me know if you guys try it. You can contribute bug reports, code, etc. at https://github.com/joshuairl/cfenv

9 Comments

  1. Billy Cravens · November 6, 2013 Reply

    Your sample code for index.cfm should be wrapped in or converted to tags. (Maybe it was and your blog code formatter ate the tags?)

  2. Billy Cravens · November 6, 2013 Reply

    Never mind, I see the cfscripts when I view source. May want to convert those with html entities so they show up :-)

    • joshua · November 6, 2013 Reply

      Billy,

      Thanks for the input. Not sure why it’s doing that. However, this article is a tad dated even though it’s only a few days old. :D

      I’m actually updating the code to make this more streamlined as we speak.

      The new instructions will be found on the GitHub README in a few minutes.

  3. Grant Copley · November 16, 2013 Reply

    This is great stuff! Not sure why more people haven’t commented. I’ve been hoping that one day the Railo community would get a tool like this. Now we do! :-)

  4. Jenny · November 23, 2013 Reply

    Hi there! I know this is somewhat off topic but
    I was wondering if you knew where I could locate
    a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having difficulty finding one?
    Thanks a lot!

  5. Chris Simmons · March 14, 2014 Reply

    This is an unbelievably cool tool. You should demo this at cfObjective() (if you are attending).

    This is probably a stupid question, but what (if anything) should I run for shutting down an environment. In other words is there some sort of ‘cfenv stop’ that I’m missing?

    Again, super super cool.

    • Joshua · March 14, 2014 Reply

      No, just hit CTRL+C to term the process. It will terminate Railo and free the system resources.

    • Joshua · March 14, 2014 Reply

      Oh! and Thanks! I always use this in my active development every day.
      It’s just so much cleaner to me.
      It’s not perfect by far, it has some shortcomings but much less shortcomings than having to install Railo globally or install ACF globally.

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax