Scenario: I am doing a spike to see the feasibility of Java application communicating to another ColdFusion application which resides on the same JVM. The intention is to create micro services using springboot on top of existing ColdFusion application.
Problem:
To do my investigation, I am using CFProxy library provided by ColdFusion. I have added the cfusion jar
to the java classpath and my Java application is compiling correctly. While running the application I am getting ClassNotFoundException
Code:
import coldfusion.cfc.CFCProxy;
public class JavaIntegration {
public String sayHelloThroughCF(String name){
String message = "";
ClassLoader classLoader = getClass().getClassLoader();
System.out.println("ClassLoader: " + classLoader);
try{
CFCProxy employeeCFC = new CFCProxy("C:\\Sites\\lb-bo-dev\\JavaIntegration\\employee.cfc", true);
Object[] args = {name};
message = (String) employeeCFC.invoke("sayCFHello", args);
}
catch(Throwable e) {
e.printStackTrace();
}
return message;
}
}
Error Message:
java.lang.NoClassDefFoundError: javax/servlet/Servlet
at JavaIntegration.sayHelloThroughCF(JavaIntegration.java:11)
at HelloWorld.main(HelloWorld.java:4)
Caused by: java.lang.ClassNotFoundException: javax.servlet.Servlet
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Note:
I am able to successfully complete the transaction if I am triggering code from ColdFusion. In this scenario, I have added the java jar to coldfusion classpath.
ie
ColdFusion--> Java --> ColdFusion
is working without any issue. Please find below the ColdFusion code
index.cfm:
<cfscript>
a = createObject("java", "cfintegration.JavaObject");
</cfscript>
<cfdump var="#a.sayHelloThroughCF('my name in cf')#"><br/>
Employee.cfc
<cfcomponent output="false" displayname="Employee">
<cffunction name="sayCFHello" access="public" output="false" returntype="String">
<cfargument name="name" required="true" />
<cfreturn "ColdFusion says hello to " & arguments.name />
</cffunction>
</cfcomponent>