3

I know it is possible to instantiate a Java class from ColdFusion, but is it possible to instantiate a ColdFusion CFC from Java code?

For instance (in Java):

ColdFusionCFC obj = new ColdFusionCFC("filename.cfc");

I am wondering if it is possible to gradually transition away from an existing ColdFusion codebase to some other JVM-based language without needing to rewrite everything right away.

danmcardle
  • 2,079
  • 2
  • 17
  • 25

2 Answers2

6

Calling ColdFusion CFCs from Java is a feature of ColdFusion 10. If you're not using CF10, you can call CFCs with remote functions as an HTTP web service.

imthepitts
  • 1,647
  • 10
  • 9
  • Awesome! I did not know that about CF10. Unfortunately, I'm on CF9. I'm not a fan of the HTTP solution, so that would be my last resort. I'm going to wait a little before selecting your answer in case anybody has a CF9 solution. – danmcardle Jul 08 '13 at 20:29
  • 2
    @crazedgremlin - Actually some version of CFCProxy has been around [since v7](http://www.forta.com/misc/cfcproxy.htm). Earlier versions might not have all the same features, but it is accessible prior to CF10. – Leigh Jul 08 '13 at 20:33
  • I always learn something new from @Leigh. I recollect Adobe making a big deal about CFCProxy for CF10, so I assumed it was a new feature. Seems like Adobe was intentionally keeping it a secret until CF10. – imthepitts Jul 08 '13 at 21:47
  • Thank you, both of you. This is exactly what I was wondering. – danmcardle Jul 09 '13 at 12:17
  • @imthepitts - Thanks. I know what you mean. I learn something new here just about every time I visit :) That is what I love about this site. – Leigh Jul 09 '13 at 16:27
1

Adobe's Ben Forta has some documentation on CFCProxy you might find useful, at: http://www.forta.com/misc/cfcproxy.htm

I also once blogged about using the CFCProxy in a CF cluster here, referring to ColdFusion 8 at the time: http://www.talkingtree.com/blog/index.cfm/2008/2/6/Using-the-CFC-Proxy-in-a-ColdFusion-Cluster

Steven Erat
  • 549
  • 2
  • 7
  • Silly question ... since cfc's need the cf servlet context, how did you test the code from java? :) – Leigh Jul 09 '13 at 16:22
  • Been a few years, but looking at my blog entry I see that the java invoker class imported the following: import coldfusion.cfc.CFCProxy; import coldfusion.bootstrap.BootstrapClassLoader; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; And then the classpath was set to include ColdFusion and JRun jar files in order to be able to reslove those dependencies: set CLASSPATH=.;%CF_HOME%\WEB-INF\cfusion\lib\cfusion.jar;%CF_HOME%\WEB-INF\lib\cfmx_bootstrap.jar;%JRUN_HOME%\lib\jrun.jar – Steven Erat Jul 09 '13 at 18:10
  • (Darn five minute time limit ..) Maybe something has changed. I tried it from an Eclipse. Just a basic java project (added all the cf9 jars and imports - cfusion, jrun, bootstrap, servlet). It compiles, but when I run it I get a "CFCServlet must be initialized" error. I will play around with it some more. Thanks for checking. (Your memory is better than mine ;-) – Leigh Jul 09 '13 at 19:43