Posts in Category "Java"

Readers’ Choice Awards – Cast Your Votes!

The Java Developer’s Journal is currently holding it’s sixth Readers’ Choice Awards. ColdFusion MX has been nominated for both “Best Team Development Tool” and “Best J2EE Application Development Framework”. JRun was nominated as “Best Java Application Server”. Distinctions like these can be a big win for us all! Cast your vote here:
http://www.sys-con.com/java/readerschoice2003/index.cfm

The ColdFusion Developer’s Journal is also hold it’s Readers’ Choice Awards, for which several Macromedia products have been nominated. Have a look and cast your vote here:
http://www.sys-con.com/coldfusion/readerschoice2003/index.cfm

Finally, Web Services Journal and XML Journal are jointly holding their Readers’ Choice Awards. Both Macromedia ColdFusion MX and JRun 4 have been nominated in the “Best App Server for Web Services” category. And ColdFusion MX has also been nominated as the “Most Innovative Application of XML”. Make your opinions known here:
http://www.sys-con.com/webservices/readerschoice2003/index.cfm

And, of course, check out the “ColdFusion & Java” story by Ben Forta while you are there.

Remember that JSP eq Java

I was talking to someone last week who needed to use some Java in his ColdFusion application, but couldn’t because of limitations with his hosting provider’s configuration which prevented him from making changes to the ColdFusion server’s classpath. I actually don’t know how much freedom developers who use shared hosting environments have when it comes to integrating Java and ColdFusion (perhaps some people can comment here), however it occurred to me that one possible work-around is to embed all your Java in JSPs (assuming the hosting provider is using ColdFusion Enterprise). JSPs get compiled into Java classes, so as long as you are doing something relatively simple, there is really no reason why you can’t simply include your Java between scriptlet tags. Scriptlet tags look like this:

<%
// java code here
%>

You can declare members (methods and variables) using declaration tags, like this:

<%!
String foo = "bar";
private String getFoo()
{
return foo;
}
%>

Use an expression tag to access members:

<%= getFoo() %>

For an explanation of all JSP tags, see:
http://java.sun.com/products/jsp/syntax/1.2/syntaxref12.html

Again, you’re not going to write an entire application like this (eventually, you are going to need access to the classpath), but in a pinch, you might find this technique useful.

Getting JRun and CFMX to Work With Java 1.4.1 on OS X

Thanks to Woojin Choi for posting information on getting JRun to work with Java 1.4.1 on OS X. I have made a couple of adjustment to what Woojin posted to match what I found to be effective:

First, back up the jvm.cfg file found here (you will need to use ‘sudo’ to make these changes):

/System/Library/Frameworks/JavaVM.framework/Versions/1.4.1/Home/lib/jvm.cfg

Edit jvm.cfg. Change this…

-client KNOWN
-jvm ALIASED_TO -client
-hotspot ALIASED_TO -client
-server KNOWN
-classic WARN

… to this …

-client
-jvm
-hotspot
-server
-classic

Edit {jrun_installation_dir}/bin/jvm.config, and change this…

java.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home

… to this …

#java.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home
java.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.4.1/Home

Give it a try and see what happens!

Making Your ColdFusion Applications More Platform Independent (Part II)

Last Friday, I made a post about writing platform-independent ColdFusion code, and specifically how important it is to be consistent with case when you are naming and referencing files since Unix file systems are case sensitive. The other practice I often see people do which keeps code from being platform independent is hardcoding file separators. The Windows file separator is a “\” (backslash character), however the file separator on Unix file systems is a “/” (forward slash character). The Macintosh file separator is a “:” (colon character), however the OS X file system will let you get away with a Unix-like “/” file separator. If your application needs to construct file paths, and you want your code to be truly platform independent, you will need to take these differences into account.

There are two good ways to make your file separators dynamic. The first is to define the system’s file separator in the Application.cfm file or other file where you keep configuration parameters. For instance, if you add this to your Application.cfm file…

<cfset request.FILE_SEPARATOR = "/" />

… rather than hardcoding slashes throughout your code, you can then simply refer to the request.FILE_SEPARATOR variable.

You can make your life even easier by letting ColdFusion (or, more precisely, Java) figure out what the system’s default file separator is for you with the following function:

function getFileSeparator()
{
var fileObj = "";
if (isDefined("application._fileSeparator"))
{
return application._fileSeparator;
}
else
{
fileObj = createObject("java", "java.io.File");
application._fileSeparator = fileObj.separator;
return getFileSeparator();
}
}

This function actually caches the file separator for you the first time you call it so that you are not instantiating a new java.io.File object each time you call it, however if you prefer to have your calling code do the caching, naturally you can re-factor the function appropriately. The point is that by not hardcoding your file separators, your code is much more platform independent, and much easier to port from one OS to another.

Couple of Useful Custom Tags

It was pointed out the other day on a list that cfinclude doesn’t let you include JSP pages and that there is no cfforward tag to forward a request on to another resource (CFM, JSP, servlet, etc.). BlueDragon apparently does have this functionality. Well, now ColdFusion does, too, with the extremely simple tags below. And ColdFusion also has getPageContext(), as well.

<!---
The includeanything tag will include any type of page, not just a
CFM template.

@attribute page (required) Relative path to the template you want
to include.
--->
<cfif thisTag.executionMode is "start">
<cfparam name="attributes.page" />
<cfscript>
getPageContext().include(attributes.page);
</cfscript>
</cfif>

<!---
The forward tag will perform a server-side redirect.

@attribute page (required) Relative path to the template you want
to forward to.
--->
<cfif thisTag.executionMode is "start">
<cfparam name="attributes.page" />
<cfscript>
getPageContext().forward(attributes.page);
</cfscript>
</cfif>