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

Java - having a different this.javaSettings.loadPath for each subfolder/module of my application

Community Beginner ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

Hi.

I have a large application that is composed of various sub directories.

All of the subdirectories share the same Application.cfc and session, but I'd like to allow each subdirectory to have its own "java_lib" folder with jar files, and to set this.javasettings.loadPaths in each subdirectory/Application.cfc, extending from /Application.cfc and just change its loadPaths.

 

The actual problem I am having, is that sometimes this work and sometimes I get a java.lang.ClassNotFoundException.

 

Is it possible to do this, or do I need to restart the application with every loadPaths change?

I understand that I could set all the paths in a single Application.cfc in my root folder, but I'd like to have these subfolders as independant as it could be from each other.

 

Or perhaps is it possible to call some coldfusion.bootstrap.something method to refresh the class loader?

 

TOPICS
Advanced techniques

Views

313

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Beginner , Dec 14, 2023 Dec 14, 2023

Hi.  Just an update for future googlers.

The issue was intermittent and I was unable to identify when it worked and when it did not.

I ended up copying the JAR to CFHOME/lib to get rid of the problem.

 

Not having the source code of ColdFusion makes it difficult to diagnose the root cause so I gave up on this unfrequent scenario in favor of the more traditional approach.

 

Thank @Charlie Arehart and @BKBK for your help.

Votes

Translate

Translate
Community Expert ,
Nov 25, 2023 Nov 25, 2023

Copy link to clipboard

Copied

That's certainly an interesting question. I'm not at a computer to test things, but I'll share a few thoughts:

  • I don't think it's well-understood what exactly is or is not inherited with extends. This goal of yours may or may not be something they intended to allow, when the javasettings eature was added in cf10.
  • Is the classnotfound happening on the class named in the this.javasettings, or on some other class? 
  • Note there are some additional properties for this loadpaths which you can set. Are you setting those or leaving them to be the defaults?
  • Is the error on a createObject/cfobject call creating an instance of the class named in the error, or on an attempt to use a method in that class? 
  • Either way, you could try wrapping the failing code in a try/catch, to get some additional diagnostics.
  • For example, you could output (to the screen or debug output, or to a log or file) the result of the cf getapplicationmetadata() function. As you may know, that returns a struct with the many settings as set per application.cfc (or cfm). You can start with a dump to see its many keys. (If somehow you can't do a dump and must write to the logs, you can use that to narrow down the key which names the javasettings. Then use that in a cflog/writelog--which can't dump a struct or other complex object.)  If you do that in a try/catch, what does that show when things fail vs when they work?

Or maybe someone else will respond with a more specific solution or other diagnostic to try. Let us know if you may try what I've proposed. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

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 Beginner ,
Nov 29, 2023 Nov 29, 2023

Copy link to clipboard

Copied

Thanks Charly for your response.

  • The exception is happening in the class in my custom java_lib folder, I am trying to use snakeyaml-2.2.jar and I get "Class not found: org.yaml.snakeyaml.Yaml"
  • I am setting javaSettings.loadColdfusionclasspath to true, loadpaths to my single directory "D:\ColdFusion2021\sandbox\wwwroot\asp\package\java_lib", reloadOnchange=true, watchExtensions=jar,class,xml and watchInterval=5.  I double checked it by printing the application Metadata in my catch block for createObject call
  • My Application variables (This.Name, This.SessionTimeout, etc) are set in my root Application.cfc.  This.JavaSettings is the only variable I am setting in the child Application.cfc
  • These javaSettings values are the same when it works as when it does not.
  • I have updated my Coldfusion 2021 to the Update 12 just in case.
  • I am using java hotspot 11.0.1+13-LTS from Oracle

 

I do not know what else to try, any pointers?

If there were a getMetadata().Reload() or similar method I could try that, but it cannot find anything similar.

I have seen in lucee docs that CreateObject have a third parameter for the JAR file, but it does not work here in Adobe CF.

Votes

Translate

Translate

Report

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 ,
Nov 29, 2023 Nov 29, 2023

Copy link to clipboard

Copied

All very interesting to hear, and understandable that it's a curious problem. Again, perhaps others will have more to share as answers. For now, I have still a couple more questions to try to help diagnose the situation.

 

So about what you are setting as that loadpath, you say in this last reply that "I am setting [...] my loadpaths to my single directory "D:\ColdFusion2021\sandbox\wwwroot\asp\package\java_lib"". First, can you confirm you are setting that as a hard-coded string? Or is the path being set from a variable? If the latter, are you dumping the value of that variable in your try/catch?

 

Second, you had said originally that "I'd like to allow each subdirectory to have its own "java_lib" folder with jar files, and to set this.javasettings.loadPaths in each subdirectory/Application.cfc". Given the path you show, D:\ColdFusion2021\sandbox\wwwroot\asp\package\java_lib, does that mean that this app is using that asp folder and some other app would use a different subfolder of that wwwroot? Of course it's not important WHAT the folder is, and this may not be germaine to the problem. I'm just connecting dots, as we try to understand your issue.

 

Finally, yes, while Lucee adds a feature on createobect/cfobject to name the library path from which to load that specific class, CF has not yet adopted that. We have only this app-level setting, for now (added in CF10).

 

I doubt more than a couple percent of CF (or Lucee) users do their own loading of java classes--or with an interest in controlling that at an app (as both CF and Lucee offer) or at the template level (as Lucee offers). I mention this both to propose why CF has not yet adopted that last feature.

 

But it also explains why there's no means in CFML (I know of) to do the reload you seek, and why there would be few people who would know of this problem and how to solve it.

 

If you don't get anywhere here, you may want to open a bug in tracker.adobe.com (Adobe folks respond in SOME forum threads here, but not most). You might also want to broaden your reach to the CFML Slack, the Facebook CF Programmers Group, and elsewhere, as there are fans of each who are active only there and not here. I list links for those in a catagory of my cf411 page, specifically at https://cf411.com/cfcommhelp. 

 

If you may get a solution somewhere, I hope you may come back and update this thread here.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

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 Beginner ,
Dec 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

Hi.  Just an update for future googlers.

The issue was intermittent and I was unable to identify when it worked and when it did not.

I ended up copying the JAR to CFHOME/lib to get rid of the problem.

 

Not having the source code of ColdFusion makes it difficult to diagnose the root cause so I gave up on this unfrequent scenario in favor of the more traditional approach.

 

Thank @Charlie Arehart and @BKBK for your help.

Votes

Translate

Translate

Report

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 14, 2023 Dec 14, 2023

Copy link to clipboard

Copied

LATEST

Curious issue. 

Before we move on, I should like to mention something I wondered about that might relate to the intermittency of the issue. What if there are occasions when the subdirectory's CFC incorrectly inherits or even fails to inherit from the root Application.cfc?  For example, ColdFusion may be following different possible paths when searching up the folders in the inheritance tree. I say this because D:\ColdFusion2021\sandbox\wwwroot doesn't look like the default web root.

 

Try the following to avoid inconsistency:

 

  1. Use the fully qualified path of the root Application.cfc in the extends attribute.
    For example, the path of my root Application.cfc is C:\ColdFusion2021\cfusion\wwwroot\workspace\CF_Project\Application.cfc. I want it to be extended by C:\ColdFusion2021\cfusion\wwwroot\workspace\CF_Project\ORM\CFC\Application.cfc. So I define this latter CFC as
    component extends="workspace.CF_Project.Application" {
        this.name = "ormSubApp";
    }
  2. In the child Application.cfc, use just one setting for Java instead of a combination of settings. That is, use something like:
    this.javaSettings = {LoadPaths = ["D:\ColdFusion2021\sandbox\wwwroot\asp\package\java_lib\"], loadColdFusionClassPath = true, reloadOnChange= "true", watchInterval=5};​




Votes

Translate

Translate

Report

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 ,
Nov 25, 2023 Nov 25, 2023

Copy link to clipboard

Copied

Yes, you can set

  • "java_lib" folder with jar files, and this.javasettings.loadPaths in each subdirectory/Application.cfc;
  • reloadOnChange to True, to load the libraries dynamically without having to restart ColdFusion.

Votes

Translate

Translate

Report

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
Documentation