Factual API and coldfusion

151 Views Asked by At

I took the java implementation of the Factual API (reference http://developer.factual.com/) and made a JAR file for factual. I did this by opening a new project in eclipse with the factual java files and then exporting to a new jar file.

I put that jar file in my coldfusion installation's /WEB-INF/lib/ folder.

After restarting Coldfusion, I tried to create a new cfobject like so

<cfscript>

     // Initialize the Java class. 
     factualClass=CreateObject("java", "src.main.java.com.factual.driver.Factual"); 

</cfscript>

I get an error indicating that it cannot find the Factual class.

Can anybody give me some guidance?

1

There are 1 best solutions below

0
On

(Summary from comments)

It sounds like you may be exporting the source files ie *.java rather than the compiled class files, ie *.class. In the Jar Export wizard, be sure to select the "Export generated class files and resources" option. (To automatically compile the project sources before expi, enable the setting: JAR packaging > Build projects if not build automatically option). If you prefer you can also find pre-compiled jars in the MVN repository.

put that jar file in my coldfusion installation's /WEB-INF/lib/ folder.

CF10+ also supports dynamic class loading via a new application level setting THIS.javaSettings.

 // Initialize the Java class. 
 factualClass=CreateObject("java", "src.main.java.com.factual.driver.Factual");

Just as a point of interest, src/main/java/ is not actually part of the libary class name. It is a standard directory structure used in Maven projects. It is probably included when exporting the sources, but not the compiled classes.

You can always verify the correct path and class name either by examining the API ie javadocs or by viewing one the source files. Package declarations are always at the top of the source file, such as on line 1 of src/main/java/com/factual/driver/Factual.java:

     package com.factual.driver; // ie "com.factual.driver"

.. and the class declaration on line 39.

     public class Factual {   // ie "Factual"

Combined that gives you the exact (case-sensitive) path to use with createObject:

     factualClass=CreateObject("java", "com.factual.driver.Factual");