tracker issue : CF-4203234

select a category, or use search below
(searches all categories and all time range)
Title:

ColdFusion application throws Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/AsDesigned

Reporter/Name(from Bugbase): A. Bakia / ()

Created: 08/05/2018

Components: Java Integration

Versions: 13.0

Failure Type: Others

Found In Build/Fixed In Build: 2018,0,01,308605 / GM

Priority/Frequency: Normal /

Locale/System: / Windows 7 SP1 64-bit

Vote Count: 0

Problem Description: 
I wrote a Java file to read a CFC wriiten in CFML. You can find both the Java file and CFC in the ColdFusion documentation: https://helpx.adobe.com/coldfusion/developing-applications/using-web-elements-and-external-objects/integrating-jee-and-java-elements-in-cfml-applications/enhanced-java-integration-in-coldfusion.html

The Java file compiled. However, when I run it, without any arguments, I get the exception java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader

Steps to Reproduce:
1. I navigated on the command line to the location of the Java file (attached). Then I compiled it as follows, using the default JDK 8 installed on my Windows machine (jdk1.8.0_181):

javac -cp C:/ColdFusion2018/cfusion/lib/cfusion.jar;C:/ColdFusion2018/cfusion/runtime/lib/servlet-api.jar;C:/ColdFusion2018/cfusion/runtime/lib/jsp-api.jar; CFCInvoker.java

The file duly compiled, resulting in CFCInvoker.class

2. I ran the class file using the command,

java -cp C:/ColdFusion2018/cfusion/lib/cfusion.jar;C:/ColdFusion2018/cfusion/runtime/lib/servlet-api.jar;C:/ColdFusion2018/cfusion/runtime/lib/jsp-api.jar;. CFCInvoker


Actual Result: 
I get the error, Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader (see stacktrace attached)

Expected Result:
No such error

Any Workarounds:
None

Attachments:

Comments:

Hi Bakia, Will you try compilation by adding another jar C:\ColdFusion2018\cfusion\lib\closure-compiler.jar and see if this works for you? Thanks Poonam
Comment by Poonam Jain
29530 | August 17, 2018 10:01:50 AM GMT
Hi Poonam, Thanks for your suggestion. I can indeed see that closure-compiler.jar contains com/google/common/cache/CacheLoader.class. When I run the Java class as before I no longer get the NoClassDefFoundError. Instead I get the following exception, but that is a different issue coldfusion.server.ServiceFactory$ServiceNotAvailableException: The Runtime service is not available. at coldfusion.server.ServiceFactory.getRuntimeService(ServiceFactory.java:117) at coldfusion.cfc.CFCProxy.<init>(CFCProxy.java:119) at coldfusion.cfc.CFCProxy.<init>(CFCProxy.java:73) at CFCInvoker.directInvoke(CFCInvoker.java:13) at CFCInvoker.main(CFCInvoker.java:27) Regards, Bakia
Comment by A. Bakia
29544 | August 19, 2018 10:51:51 AM GMT
Hi Bakia, Yes, you will hit this issue because runtime service is not available. You can place the class file in WEB-INF ->classes and restart CF server. after that use CFM code to invoke the method.  <cfscript> class = CreateObject("java","CFCInvoker"); </cfscript>   When you will dump the class variable you will see the methods. You can invoke the methods in cfm and get the data. Thanks Poonam
Comment by Poonam Jain
29545 | August 20, 2018 03:53:02 AM GMT
Thanks, Poonam. I am aware of how to get the Java classes going in ColdFusion. However, my intention is to run a CFC with 100% Java code. That is, without ColdFusion. The exception coldfusion.server.ServiceFactory$ServiceNotAvailableException implies that the variable runtime (of type private static RuntimeService) in coldfusion.server.Servicefactory is null. I didn't expect that.
Comment by A. Bakia
29554 | August 20, 2018 07:43:31 PM GMT
Hi Bakia, You cannot invoke CFC through java code directly as you might land up on dependencies likes this . i would suggest you  expose it as webservice or restservice and then use it outside.   Thanks Poonam
Comment by Poonam Jain
29572 | August 21, 2018 08:47:28 AM GMT
Hi Bakia, If you are able to generate the class file, shall I go ahead and close this bug. Thanks Poonam
Comment by Poonam Jain
29607 | August 23, 2018 04:05:17 AM GMT
Hi Poonam, Generating a class wasn't a problem. Running the class file was. You answered the original question. The solution is: add C:\ColdFusion2018\cfusion\lib\closure-compiler.jar to the classpath. That said, I was surprised to see the commercial name "com/google/" in the error message.
Comment by A. Bakia
29608 | August 23, 2018 05:00:11 AM GMT
Bakia, yeah, I was talking about original question.C:\ColdFusion2018\cfusion\lib\closure-compiler.jar is a open source library and exception is thrown by it during class compilation which you are doing through java code. you will not get his error if you will use pure CF code for accessing the function. Thanks Poonam
Comment by Poonam Jain
29612 | August 24, 2018 12:07:01 PM GMT