I've been compiling ColdFusion applications on and off over the years for various reasons, usually on my server or another server that I have access to.
Recently I've been compiling for deployment to an external server that I've not had access. I ran into a few problems with the resulting compiled code not running on these servers while it runs perfectly locally.
To start at the beginning, I've often simply pre-compiled an application in place, so that it need not compile the templates on first access. Occasionally I've compiled for source-less deployment. Usually under those circumstances I've had access to the server, where I've simply loaded source code onto the server, compile, dropped the compile code into place and then removed the source.
Its not pretty. Its not an ANT script, but it works for occasional source-less deployments.
Recently though I've had a few source-less deployments that meant that I had to hand over the compiled code to a client in an archive of some kind or I only had ftp/sftp access to the server. I've also been trying to streamline updates to a client's server that we do have access to and to be honest I had no end of bother.
I found that sometimes compiled code would simply fail. Code would mostly work, but then there would be the odd template that would throw an error for no apparent reason. I couldn't work out what the problem was. I compiled the code everyway I could think of and still there were odd errors in unexplained places with core tags, such as cfdump.
In the end I took the compile.bat file apart line by line. It was only when I did this that I realised that an assumption I'd made was incorrect.
The assumption was that the compile was using the JVM that the compiler was using was the one being used by the ColdFusion Server that was providing the bootstrap, libraries and updates that will be used in the compile.....
Ass - u - me...... Need I say more...
The JVM that is used during the compile is not the one that is associated with the server. The JVM that is used during the compile is the default for the computer on which you running the batch file.
Having realised this I rewrote the compile.bat file to use a JVM specified in the command line. That compile.bat is attached to this blog post. Feel free to use it. If you have updates and fixes for the batch file, please do send them to me. I would interested to tidy this up and make it more useful.
So how do you use this batch file? The original batch file is called like this :
My version of the batch file is called like this :
compile.bat -version 1.6.0_18 d:\deploy\mysite d:\deploy\compiledsite
As with the official cfcompile batch file, you will need to edit the file to set the path to ColdFusion home directory, the WEB-INF folder for that server and the location of the JRun jar file. I've left some of mine in the batch file, so that you have an idea of where you might find them on your computer.
The batch file assumes that you have the JDKs installed under c:\Program Files\Java\ and the folder that the JDK lives in is prefixed "jdk". When you enter the version number that you want to compile with, as it is in the example above, the script will use this to find the bin directory and the java exe with which it will compile your ColdFusion code.
The second parameter is the folder of source ColdFusion code that you want compiled. If you don't specify the output directory, your compiled code will be placed in "d:\deploy\mysite_sourceless"
This script will allow you to use any JDK you have installed to compile your code before handing it over to a client or other external organisation.
The last thing I would suggest when compiling applications to be deployed sourcelessly. Not only should you make ensure that the JDK you use to compile your application is the same as the one being used by ColdFusion on the deployment server, but you should also make sure that all the security updates and server patches have been applied to both your local server and the deployment server. The closer the two server are to one another the more likely your sourceless application will run correctly.