Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Checking Type of java classes created with Scala

New Here ,
Dec 16, 2012 Dec 16, 2012

Hi.

I've created a simple class in Scala and packed it into a .jar file. I have no problems loading it into ColdFusion and running its methods.

Here is a copy of cfdump of the created object:

object of example.HelloWorld
Class Nameexample.HelloWorld
MethodsMethodReturn Type
Country()example.HelloWorld$Country$
cn()example.HelloWorld$Country
countriesList()scala.collection.immutable.List
countriesMap()scala.collection.immutable.Map
getCountryByCode(java.lang.String)scala.Option
ja()example.HelloWorld$Country
ru()example.HelloWorld$Country
us()example.HelloWorld$Country

But I have problems with isInstanceOf function with this object. If I run:

HelloWorldApp = CreateObject("java","example.HelloWorld");

writeOutput(isInstanceOf(HelloWorldApp,"example.HelloWorld"));

I get false as a result, but it should be true, right? The class does get loaded properly by CreateObject function.

Is there a workaround? The cfdump tag somehow manages to get the proper type of the object which it displays in the Class Name field of the dump table.

Thank you.

5.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 28, 2012 Dec 28, 2012

If you're up for it, I just thought of another test. At least for the time being. I am assuming the JAR file is at the original location,

C:\ColdFusion10\cfusion\wwwroot\org\cfjava\jars\cfjavatest.jar

In Application.cfc, comment out all the lines involving this.javaSettings. Go to the Java and JVM page in the Administrator. Add the following to the classpath:

C:/ColdFusion10/cfusion/wwwroot/org/cfjava/jars/;C:/ColdFusion10/cfusion/wwwroot/org/cfjava/jars/cfjavatest.jar

Press the button to submit the changes. To be sure, restart ColdFusion.

Any joy?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2012 Dec 29, 2012

Thanks for the JAR file. Here follows my progress report.

As a first test, I commented out the code this.javasettings=.... I unpacked the JAR file and copied its contents (example and scala directories) to C:\ColdFusion10\cfusion\wwwroot\WEB-INF\classes\. I restarted ColdFusion. When I run your original isInstanceOf code, I get a Yes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 30, 2012 Dec 30, 2012

I have been able to reproduce the issue (failure of isInstanceOf with dynamic Java settings) time after time. I am beginning to wonder whether you have uncovered a bug. However, I did find another positive result.

Comment out the code this.javasettings=.... Move the file cfjavatest.jar to the directory,

C:\ColdFusion10\cfusion\wwwroot\WEB-INF\lib\

Restart ColdFusion. When you run the original isInstanceOf code, you get a Yes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 31, 2012 Dec 31, 2012
LATEST

@Kirill_Grishin

I decided to round this up before the end of the year. I am sorry I haven't been able to do better than find the above workarounds.

IsInstanceOf(helloworldapp,"example.HelloWorld")) continues to return No for dynamic Java settings. I have reproduced the behaviour using every conceivable directory structure in the loadPaths attribute in this.javaSettings. As far as I can see, what you have discovered is a bug.

Please consider filing a bug report. In fact, someone reported a similar bug (3121307) as far back as February 2012, when ColdFusion 10 was still in pre-release beta. Apparently that problem remains unsolved!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 23, 2012 Dec 23, 2012

Hang on a minute! I have this niggling feeling ColdFusion's isInstanceOf might be expecting the qualified name jars.example.HelloWorld.

Just for giggles, run the original index.cfm page one directory up, in the jars directory. That is, make a copy to

C:\ColdFusion10\cfusion\wwwroot\org\cfjava\jars\index.cfm

and run it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources