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.
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…
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
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. Let me know if you guys try it. You can contribute bug reports, code, etc. at https://github.com/joshuairl/cfenv