A Beginners Guide to Java Integration in Coldfusion

Download Report

Transcript A Beginners Guide to Java Integration in Coldfusion

Rick Root

It just doesn’t seem right to have a slide with
bullet points that prompt me to talk about
myself.



Extend ColdFusion with “core” java
Extend ColdFusion with external java libraries
We will not talk about JVM tuning, writing CFX
Custom Tags in Java, or writing your own Java
classes.



ColdFusion newbs
Never really used Java in ColdFusion
Just here for the networking





Java Objects
Data Types
Creating and Initializing Java Objects
JavaCast()
Examples

It all starts with java.langObject
Java objects have methods, so ColdFusion
variables do to.

Example 1


Strictly typed, very picky!
Don’t assume!

Example 2


In Java, create and initialize all at once, ie:
foo = new ClassName(arguments)

In CF, use CreateObject() and init() method
foo = CreateObject(“java”,”path.to.ClassName”);
foo.init(arguments);

Multiple constructors / overloaded methods
foo.init(“string”);
foo.init(someint);


Force a ColdFusion variable to be a specific
data type
Example 3 & 4

Object creation is expensive
Strings are immutable
Java StringBuffer object can help!

Example 5





Where to Install
Java Loader
Examples

Standalone:
<cfroot>/lib

Multi-server Install, all instances:
<jrunroot>/servers/lib

Multi-server install, specific Instance:
<jrunroot>/servers/<instancename>
/cfusion.ear/cfusion.war
/WEB-INF/cfusion/lib

Anywhere you want!

javaloader.cfc – Mark Mandel
Access classes without requiring them to be
in the server CLASSPATH
Javaloader.riaforge.org

Example 6





Generating Excel Files
Creating delimited text files
Extracting JPEG image metadata

Apache POI – API to interface with Microsoft
Office files
http://poi.apache.org
Create Excel files in native format
Use more Excel features

Example 7







JavaCSV makes it easy
Choose your delimiter
Automatic quoting when data contains your
delimiter or even newlines
Example 8

Digital cameras store lots of metadata in
captured images
Timestamp
Exposure
Camera model
Lots of stuff I don’t understand!

Example 9







Rick Root
[email protected]
http://www.opensourcecf.com/