我一直在尝试从Java调用ColdFusion组件,然后执行以下操作:
http://www.forta.com/misc/cfcproxy.htm
Java版本: 1.8.0_141
我在构建路径中添加了以下所需的jar:
cfmx_bootstrap.jar
cfusion.jar
javax.servlet.jsp.jar
javax.servlet-api-3.0.1.jar ( Servlet jars added as on running java program it was throwing ClassNotFound errors )
在此之后添加 Test.java :
import coldfusion.cfc.CFCProxy;
public class Test {
public static void main(String args[]) throws ClassNotFoundException {
Test test = new Test();
System.out.println(test.invoke().toString());
}
public String invoke() {
String cfOp = null;
try {
// Instantiate CFC
CFCProxy myCFC = new CFCProxy("D:\\practice\\cf_java.cfc", true);
// Build arguments array
Object[] myArgs = { "Java invocation!" };
// invoke method from CFC. It returns a string.
cfOp = (String) myCFC.invoke("getData", myArgs);
} catch (Throwable ex) {
ex.printStackTrace();
}
return cfOp;
}
}
然后在 / JavaClass /
下添加 Test.class的Application.cfc:
<cfcomponent>
<cfset THIS.name = "CFTest">
<cfset THIS.javaSettings = {
LoadPaths = ["\JavaClass\"],
reloadOnChange=true,
watchInterval=10,
reloadOnChange = true
}>
</cfcomponent>
cf_java.cfc:
<cfcomponent>
<cffunction name="getData" returntype="string">
<cfargument name="msg" required="Yes">
<cfreturn "I am alive!">
</cffunction>
</cfcomponent>
最后将Test.java作为java应用程序运行,我得到了以下内容:
java.lang.RuntimeException: CFCServlet must be initialized
at coldfusion.cfc.CFCProxy.<init>(CFCProxy.java:121)
at coldfusion.cfc.CFCProxy.<init>(CFCProxy.java:73)
at Test.invoke(Test.java:15)
at Test.main(Test.java:7)
Exception in thread "main" java.lang.NullPointerException
at Test.main(Test.java:7)
我错过了什么吗?任何建议!
另外,来自Adobe Docs:
要调用CFC,ColdFusion类加载器必须是当前的类加载器。
任何人都可以解释一下或分享一些链接吗?