Hi,
I’m sure I’m missing something obvious here, but I hope somebody may be able to help:
I’ve got a base component base.cfc with an init()
method that loads some Java classes. The JAR files for those classes are stored in a folder /lib/
that is relative to the location of that base.cfc.
So in this init-method in the base.cfc there is code like this:
partnerType = createObject( "java", "com.amazon.paapi5.v1.PartnerType", variables.oSDK.libPath ).ASSOCIATES;
variables.oSDK.libPath
obviously needs to point to this /lib/
directory. So in my first attempt, I just set this with
variables.oSDK.libPath = "#getDirectoryFromPath(getCurrentTemplatePath())#/lib/";
For anything directly using an instance of base.cfc, this works.
Now this base.cfc is being extended by some other components that may reside anywhere in the file system - the extends parameter is using a mapping to point to that base.cfc. There may be child components that explicitly call SUPER.init() in their own init method.
In this case, getDirectoryFromPath(getCurrentTemplatePath())
seems to resolve to the current path of the child component, not to the path of the base.cfc
. If the child component doesn’t reside directly next to base.cfc, this causes a problem, as the path to the /lib/
directory is resolved incorrectly.
The getCurrentTemplatePath()
statement is not in the child component, nor does the child component override the value of variables.oSDK.libPath
. Still, the path returned by getCurrentTemplatePath()
always seems to resolve to the component being called instead of the component where the actual getCurrentTemplatePath()
is being called.
I therefore need to hardcode the library path for it to resolve to the correct directory under any circumstance. Is there a workaround that would allow me to call the Java library under the correct path relative to the base.cfc in it’s init(), even if the base.cfc is being extended from somewhere else?
I’m on Lucee 5.4.3.15, if that matters.
Kind regards
Markus