Problems loading/using jsoup in ColdBox/Lucee - coldfusion

there are many posts on issues similar to mine, but none of them has helped. Not sure what I am doing wrong. I am trying to load the jsoup jar using this.applicationSettings, and I keep getting an error. Specifically:
Application.cfc:
this.javaSettings = {
loadPaths = [ ".\lib" ],
loadColdFusionClassPath = true,
reloadOnChange= false
};
Yes, jsoup-1.11.2.jar is in \lib for that application. I tried \lib\ too; no joy.
But every time I try to use
myJsoup = createObject("java", "org.jsoup.Jsoup");
or
myJsoup = createObject("java", "org.jsoup.Jsoup").init();
I get an error,
cannot load class through its string name, because no definition for the class with the specified name [org.jsoup.Jsoup] could be found
Does not matter what function I place the init code in -- handler or model -- or if I put it in a cfscript or cfset. I can even put it in index.cfm and still get the same error. Does not matter what I restart or how many times I restart it. It is as if ColdBox and/or Lucee just refuses to acknowledge the existence of the jar file or something. What gives?
I sure would appreciate any tips! Thanks in advance!

I'm not sure if this is just bad documentation out in the wild, a shortcoming of my own understanding or simply a bug in ColdFusion and Lucee...
I put together a simple test and recreated what you're seeing in both engines. I originally figured there must be an issue with paths in Lucee but ACF produces the same error.
Looking at existing code I use, it seems I always populate the full path to the JAR/Class files.
I often do something like this (which works) to load everything in the /lib directory:
this.javaSettings.loadPaths = directoryList(expandPath("/lib"));
Which in turn sets the value to [ "/mypath/lib/jsoup-1.11.2.jar" ].

Related

Can't refresh CFC CF9 when using an application.cfm

I was charged with making some modification to an old application, and I created a new page which was being passed a URL parameter page_name, which is a you guessed it a name of a page with .cfm appended. So, in my haste, I continued using it, and was building out my CFC and using the page_name as the identifier for a record. Then I realized that there is a possibility of that name being duplicated in the table, and changed that url parameter to use the page_id, which is unique. I modified my CFC to use the new key, and nothing worked. So I started going through my code and figured I made a typo, started commenting things out, and finally dumped out my CFC object and voila, none of the edits I made were actually being used. This was fairly obvious, since page_name was a string, and page_id was numeric.
So I started googling,The first thing I saw as adjust things in the CFAdmin. I don't have access to it, and restarting the server isn't an option since I'm using an RDS to live code. The next thing I tried was to add applicationStop(), onApplicationStart(), to my Application.cfc. Well the problem is that the Application.cfc, is actually an Application.cfm. So after fiddling with the <cfapplication ... > tag, and nothing being updated, I'm here asking for help.
So is there a quick fix for this? Should I go ahead and create an application.cfc? I hope I explained myself, and sorry for all the text.
Confirm that your cfc is bound to either the session or application scope.
If it is, then you can rename the application in application.cfm and it will reset the object.
If your cfc is NOT bound to session or application scope, you have a cacheing issue. You need to go the the CF admin -> Server Settings -> Cache tab and uncheck component cache and possibly some others.
For further recommendations, ColdFusion Components Inheriting Functions Of Others
Sounds like you have been painted into a corner. Last option IF you have access the the server it self and can get into the C:\ or whatever drive that ColdFusion have been installed on, you can just manually delete the generated Java Class files that the server is using that has the old code. When ColdFusion sees there is no Class file it will recompile the newly changed file and whoa black betty go bam-a-lam your changes will be in production.
For more information here is an posting you can read up on: http://kalyan-coldfusion.blogspot.com/2010/08/how-coldfusion-works-and-its-key.html
Cheers

Coldfusion CFC Mapping to external directories with CFCs that reference other folders

I've done some poking around and trial and error but I'm not coming up for a solution to this problem I have.
I have a folder structure like this (example)
Application.cfc
Objects\
Object.cfc
Utilities\
Util.cfc
API\
Resources\
index.cfm
Application.cfc
I have one site that points to the API folder (http://api.site.com) and another that points to the overall root (http://site.com)
From Api\Resource\index.cfm. I'm trying to createObject() on Objects\Object.cfc. I set up a mapping, either in CF Admin, or API\Application.cfc with this.mappings["/SiteRoot"] = "C:\wwwroot". Inside the index.cfm I do createObject("component","SiteRoot.Objects.Object"). This correctly access the Object.cfc.
The issue I'm having is that it fails because Object.cfc instantiates the Utilities\Util.cfc just by createObject("component","Utilities.Util"). The error is that Utilities.Util cannot be found.
There are other files in the very bottom root that can obviously call Object.cfc with no problems since it just goes into the Utilities folder naturally.
Any suggestions Or do I really need to just break the API Folder out of this root entirely?
Thanks!
UPDATE
It's not letting me answer my own question just yet but I wanted to post here before others chimed in.
Despite reiniting the application and restarting the application server, once or twice it wasn't working. Then suddenly, it just went and worked as I would have expected. Object.cfc could find Util.cfc correctly based on it's relative path.
I gave upvotes to those who responded as they were perfectly viable alternatives and solutions and would have gone with one of them had this not just started working. Demons, I tell you. Demons.
Thanks!
I think I would change your second create object call (the utilities one) to createObject("SiteRoot.Utilities.Util") ? Making sure that one mapping "governs" the starting point for all the objects no matter where instantiated.
If you really cannot change your code then just create a ColdFusion mapping called Utilities pointed at the Utilities folder.

CFEclipse doesn't recognize structName in cfimage tag

This code:
<cfimage action="info" structName="imageInfo" source="#imagePath#">
is giving this error:
The attribute 'structName' is required for the tag. (Found:
[source, structname, action])
When I run this code in CFBuilder - everything is OK, but I must use CFEclipse.
What should I do (I use CF9)?
Thank you for your answers!
Of course this problem won't prevent you from running your application on ColdFusion. It is just an IDE warning that something is wrong.
You have a few options.
Try using a lowercase N in structName. i.e. structname. ColdFusion is not case-sensitive, but Java is, and CFEclipse is a Java application.
If that does not work, then it probably means that the dictionary file that drives the code assist is not correct. You can go earch forthose XML files and update them to include that attribute.
You can use CFBuilder. I know you said you can't, but I have to question why. You know there is a free version that is just as good as CFEclipse, right?
The problem is that there's a casing glitch in that file Peter mentions. There's one reference to "structName" to define the attribute itself, and another "structname" which is in the list defining which attributes are needed for action="info". If you make them both the same, then restart Eclipse, you should be OK (that's I've needed to do to make the error indicator go away).

ColdFusion 8 JavaLoader LingPipe or OpenNLP, how do I init it?

I'm using the JavaLoader.cfc. I've used it before, but am having trouble understanding how to get one of these libraries to respond to me.
I've placed the JAR files into my java folder. I've created the "JavaLoader" object and passed the "paths" to it. But it keeps saying it cannot find the class names in the jar files or something along those lines...
The requested class could not be found. The requested class
opennlp.tools.sentdetect could not be found in the loaded
jars/directories.
I recognize I'm a total n00b when it comes to Java and how to tie it in with ColdFusion. I'm sure it's something stupid that IF I KNEW I could probably use any JAR file at my disposal...
Please help if you can!
I checked the OpenNLP javadocs here and it seems that opennlp.tools.sentdetect has no constructor so that's why it returns an error. Which method do you want to call?
I've done a simple example to detect sentences but for that you need to get the english model available here :
<cfscript>
// load NLP jar libraries
sourcePaths = [expandPath("opennlp-tools-1.5.0\opennlp-tools-1.5.0.jar"),expandPath("opennlp-tools-1.5.0\lib\maxent-3.0.0.jar"),expandPath("opennlp-tools-1.5.0\lib\jwnl-1.3.3.jar")];
javaloader = createObject("component", "javaloader.JavaLoader").init(sourcePaths);
// load our model (here english model)
// you can create your own model using the TrainerTool
inputFile = ExpandPath("en-sent.bin");
modelIn = createObject("java", "java.io.FileInputStream").init(inputFile);
model = javaloader.create("opennlp.tools.sentdetect.SentenceModel").init(modelIn);
// let's try the sentence detector
sentenceDetector = javaloader.create("opennlp.tools.sentdetect.SentenceDetectorME").init(model);
sentences = sentenceDetector.sentDetect("I love working with Java in ColdFusion! CF rocks, really! But sometimes working with Java libraries is a bit tricky :-)");
</cfscript>
<cfdump var="#sentences#">
Have fun! :-)
No Java expert here either , but I did get POI to work by following Rays instructions here There's two articles. He covers setting up Javaloader
You issue may just be in the path to the JAR. Also be sure that you are passing the path to the JAR file as a string in an array.
Tip 1: You do not need to place the file in your java folder. Being able to place the JAR file in any directory (application root perhaps), is what JavaLoader gives you the power to do. Otherwise you might as well not use JavaLoader and just place the JAR files into the JVM classpath.
Tip 2: Be sure that initialize JavaLoader into the server scope, as it will reduce your overhead dramatically.

Cannot find CFML template for custom tag

I am not a ColdFusion coder. Doing a favor for a friend who ported his CF site from a Windows server to Unix on GoDaddy.
Site is displaying error:
Cannot find CFML template for custom tag jstk. ColdFusion
attempted looking in the tree of installed custom tags but did not
find a custom tag with this name.
The site as I found it has at document root /CustomTags with the jstk.cfm file and a set of files in cf_jstk
My Googling located this:
You must store custom tag pages in any one of the following:
The same directory as the calling page;
The cfusion\CustomTags directory;
A subdirectory of the cfusion\CustomTags directory;
A directory that you specify in the ColdFusion Administrator
So I have:
Tried creating placing /CustomTags in /cfusion/CustomTags
Tried copying /cfusion/CustomTags to above document root
Tried copying jstk.cfm and subfolders into same directory as calling file(index.cfm)
Update: Per GoDaddy support I have also tried adding the following to no effect: <cfmodule template="CustomTags/jstk.cfm">
Can any one give me some tips on this or should I just tell my guy to look for a CF coder?
Thanks!
I don't know how GoDaddy is setup, so as a quick test, please do the following:
Create file test.cfm in the webroot with contents:
<cf_testtag/>
<cfoutput>test</cfoutput><cfabort/>
Create file testtag.cfm in the webroot with contents:
<cfdump var=#ThisTag# />
Then in a browser visit the test.cfm page.
You should get two debug dumps, followed by the 'test'; this will confirm that custom tags in general are working.
If that works move the testtag.cfm to the CustomTags directory, and see if you get the same behaviour or an error.
If this produces an error, for CF8 and above, you can add <cfset This.CustomTagPaths = "/CustomTags" /> inside the Application.cfc file (assuming there is a App cfc and not an Application.cfm) to ensure that directory is checked for tags.
It is possible to convert Application.cfm to Application.cfc - how easy this is depends on how complex the code is in there - might be something you could figure out, or might need an experienced CF dev, it depends.
Depending on the outcome of this, we can attempt to debug why the jstk tag isn't working (unless one of the above solves it).
In an effort to check the simple things before worrying about complex things:
Remember that filenames on *nix systems are case sensitive, but on windows are not.
For example, a windows server will pick up "application.cfm" but a linux server won't. It requires "Application.cfm".
Check to make sure all filenames/paths are the correct case.
Normally, CFML check every custom tags in current directory first, if not found, second is in CFMX8/customtags/.