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

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.

Related

Problems loading/using jsoup in ColdBox/Lucee

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" ].

Not visualizing ASCII STL file correctly

My problem seems similar to Not able to visualize a loaded data , but I have no console errors and I have already added the '-allow-file-access-from-files' flag to my Chrome Browser. Here's my Java coding,
window.onload = function() {
var r = new X.renderer3D();
r.init();
pros = new X.mesh();
pros.file = 'file:///C:/Users/Nathan/Downloads/JB Farmer STL ACII.stl';
pros.caption = 'Prosthetic';
r.add(pros);
r.render();
};
Should I "play around" with with camera position, I know I have to do that in Three.js.
Maybe the model needs normals? I'm not sure if it does or not. I haven't worked with 3D modeling, besides Three.js.
Update: Ummmm, I'm not sure what is going on with this, but I realized that XTK generated 2 canvases . I looked at the first two Lessons and they have one.
^ Now eliminated the extra canvas, must have copied a piece and that was in there.
For the moment, the loader of xtk doesn't seem to be done for local. I mean : it uses an XMLHttpRequest (XHR) to get the file with a GET request. First of all the request must be sent to something that can handle it (a server or localhost emilated by Wamp or equivalent). Then let's imagine if one broswer, no matter what one, allows XHR on a file at client side by his url, and imagine I'm a pirate and you come on my website. I know Windows well, I know in C:/Windows/System32 there always is a file where I can find your personals data. What do I do ? An XHR ! You've been hacked. It's a story but you see the idea.
That's why the only ways allowed by browsers to access local files are HTML5 File API & HTML5 Drag&Drop API (unfortunately...). Actualy a way to go through that limitation is having binary code at the client side (flash, java applet). The client is the only one who can ask to open a file or drop a file, so the browser is sure there won't be any security failure because of him.
So you should test it with something like Wamp and access your file with an url like "http://localhost/.../myfile.stl" or the relative url "/.../myfile.stl", or do the following if you realy want local files.
A few weeks ago I wrote my own parser for a private format for xtk and from local file, it worked well, I just used HTML5 APIs to read the file and get a String or BinaryArray from it and then wrote a parser that transformed it in a X.mesh. So I think the best would be to extend the X.loader for HTML5 file APIs, or like me to manualy load the file.
The following jsFiddle from Haehn helps : here !
What happens if you modify the filename with no space?
JB Farmer_STL_ACII.stl instead of JB Farmer STL ACII.stl

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.

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/.

ColdFusion Google Adwords Business Component Error

I am using Martin Orth's ColdFusion API for Google Adwords. I have been able to fix some errors to get the API working in most cases, but am running into a roadblock when I try to use the business.cfc component. I try to create the component the same way I have successfully created them for other components of the API with the syntax:
cfset oBusiness=createObject("component","com.google.adwords.api.v12.business")>
The results in a:
coldfusion.xml.rpc.CFCInvocationException: [java.lang.ClassNotFoundException : com.google.adwords.api.v12.business][coldfusion.runtime.CfJspPage$NoSuchTemplateException : Could not find the ColdFusion Component or Interface long.]
even though the business.cfc file is located as the specified path and has not been modified. Has anyone been able to get this component to work? If so, can you post a copy of your business.cfc file? Thanks in advance.
I just rewrote the entire code minus comments and hints (in past files there were many illegal chars) in a new file and it worked fine.
There is a new version (V201101) of the AdWords API library for ColdFusion at http://www.cfsolutions.de/coldfusion_adwords_api/docs/index.cfm