Calling a .jar from ColdFusion
11,617
Solution 1
Have you restarted the Coldfusion Service?
Even when in the class path, jars are only loaded at server start.
Info moved up from the comments:
- Make sure the file is in the System class path, or in the one of the configured class paths of ColdFusion.
- As for the class name parameter of
CreateObject()
: The class name starts within the jar. Open it like a .zip file and look at its structure. The dotted path mimics the folder structure, so if the Server still complains, you must be missing something in the dotted path.
Solution 2
Have you considered using JavaLoader?
Author by
Gene R
I'm a software developer. I work full time for a publishing company in Charlotte, NC. I'm married with 2 teenagers.
Updated on August 09, 2022Comments
-
Gene R over 1 year
I have a .jar file that i've placed in my D:\Coldfusion8\wwwroot\web-inf\lib\ directory. The file is abcdef.jar
This is my first time doing this, not sure what the path should be in my createObject().
<cfset abcObj = createObject("java","com.abcdef") /> <cfset result = acbObj.doStuff("123456") />
But when I run it, I get
Object Instantiation Exception. Class not found: com.vp4jo_b
What am I missing in the path?
-
Gene R over 15 yearsI have. My confusion comes in where the "com" starts. I got that from an example on the web. As I said, my .jar is in D:\Coldfusion8\lib\
-
Tomalak over 15 yearsThe "com" starts within the jar. Open it like a .zip file and look at its structure. The dotted path mimics the folder structure, so you must be missing something in the path.
-
Gene R over 15 yearsOk, so going back, where do I tell Coldfusion to even look for the .jar file?
-
Gene R over 15 yearsNevermind. I had the .jar in the wrong directory. I moved it, restarted CF, followed your advice about the Path, fixed my createObject and Voila... THanks!
-
modius over 15 yearsJavaLoader is definitely the way to go. That way you can place the Java class/lib where you like rather than relying on the class path for your specific installation.