Copy link to clipboard
Copied
Good afternoon,
I would like to think this question has been asked and answered before but I'm not having the best time naving the updated forum. Anyway, I have a compiled Java application that I cannot read with CF. This is my error message: Object Instantiation Exception. Class not found. My jar exists in here: <cfset THIS.javaSettings = {LoadPaths = ["/ReaderRFID/lib"], loadColdFusionClassPath = true, reloadOnChange=false}/>.
My output page:
<cfset jar = CreateObject("java", "AlienClass1ReaderTest")>
<cfset readTags = jar.AlienClass1ReaderTest>
<cfoutput>
#readTags#
</cfoutput>
The class should be called from the jar but nothing happens. Any help is always appreciated. Thanks!
On the command-line, you would run it like this:
> java -cp C:\ColdFusion10\cfusion\wwwroot\ReaderRFID\lib\AlienRFID.jar AlienClass1ReaderTest
One way to translate this into Coldfusion is:
<cfexecute name="java" arguments="-cp C:\ColdFusion10\cfusion\wwwroot\ReaderRFID\lib\AlienRFID.jar AlienClass1ReaderTest" outputFile="#expandpath('output.txt')#" ></cfexecute>
Java done.
That would run the code and store the output in the current directory as the file output.txt.
Copy link to clipboard
Copied
Use <cfset THIS.javaSettings = {LoadPaths = ["/ReaderRFID/lib/AlienClass1ReaderTest.jar"], loadColdFusionClassPath = true, reloadOnChange=false}/>, then instantiate the class, not the JAR.
Copy link to clipboard
Copied
BKBK,
I made some corrections:
<cfset THIS.javaSettings = {LoadPaths = ["/ReaderRFID/lib/AlienRFID.jar"], loadColdFusionClassPath = true, reloadOnChange=false}/> (AlienRFID is the jar)
Class:
<cfset readTags = CreateObject("java", "AlienClass1ReaderTest")/>
Classpath (added through Admin):
C:\ColdFusion10\cfusion\wwwroot\ReaderRFID\lib\AlienRFID.jar,
C:\ColdFusion10\cfusion\wwwroot\ReaderRFID\bin\com\alien\enterpriseRFID\examples,
C:\ColdFusion10\cfusion\wwwroot\ReaderRFID\src\com\alien\enterpriseRFID\examples
Error Message:
The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.
The following information is meant for the website developer for debugging purposes. | ||||||||||||||||
Error Occurred While Processing Request | ||||||||||||||||
|
Copy link to clipboard
Copied
I got this to work <cfset readTags = CreateObject("java", "com.alien.enterpriseRFID.examples.AlienClass1ReaderTest").init()/> but I'm not getting any string values.
This is what shows on screen: com.alien.enterpriseRFID.examples.AlienClass1ReaderTest@684c72e3
Tag tagList[] = reader.getTagList();
if (tagList == null) {
System.out.println("No Tags Found");
} else {
System.out.println("Tag(s) found:");
for (int i=0; i<tagList.length; i++) {
Tag tag = tagList;
System.out.println("ID:" + tag.getTagID() +
", Discovered:" + tag.getDiscoverTime() +
", Last Seen:" + tag.getRenewTime() +
", Antenna:" + tag.getAntenna() +
", Reads:" + tag.getRenewCount()
);
}
}
I need to see the results of tagList. Thanks!
Copy link to clipboard
Copied
djkhalif wrote:
I got this to work <cfset readTags = CreateObject("java", "com.alien.enterpriseRFID.examples.AlienClass1ReaderTest").init()/> but I'm not getting any string values.
This is what shows on screen: com.alien.enterpriseRFID.examples.AlienClass1ReaderTest@684c72e3
Yes, you are just printing out the ID of the Java object, which is what init() returns. The code you show us appears in some method. That is the method that you have to invoke with the readTags object, instead of init().
Copy link to clipboard
Copied
When I use Main as the method I get method not found
Java:
package com.alien.enterpriseRFID.examples;
import com.alien.enterpriseRFID.reader.*;
import com.alien.enterpriseRFID.tags.*;
/**
* Connects to a Reader on COM port #1 and asks it to read tags.
*
*/
public class AlienClass1ReaderTest {
/**
* Constructor
*/
public AlienClass1ReaderTest() throws AlienReaderException {
AlienClass1Reader reader = new AlienClass1Reader();
// reader.setConnection("COM1");
// To connect to a networked reader instead, use the following:
reader.setConnection("192.168.1.70", 23);
reader.setUsername("username");
reader.setPassword("password");
// Open a connection to the reader
reader.open();
// Ask the reader to read tags and print them
Tag tagList[] = reader.getTagList();
if (tagList == null) {
System.out.println("No Tags Found");
} else {
System.out.println("Tag(s) found:");
for (int i=0; i<tagList.length; i++) {
Tag tag = tagList;
System.out.println("ID:" + tag.getTagID() +
", Discovered:" + tag.getDiscoverTime() +
", Last Seen:" + tag.getRenewTime() +
", Antenna:" + tag.getAntenna() +
", Reads:" + tag.getRenewCount()
);
}
}
// Close the connection
reader.close();
}
/**
* Main
*/
public static final void main(String args[]){
try {
new AlienClass1ReaderTest();
} catch(AlienReaderException e) {
System.out.println("Error: " + e.toString());
}
}
} // End of class AlienClass1ReaderTest
CF:
<cfset myObj = CreateObject("java", "com.alien.enterpriseRFID.examples.AlienClass1ReaderTest").main()>
Error:
The following information is meant for the website developer for debugging purposes. | ||||||||||||||||
Error Occurred While Processing Request | ||||||||||||||||
|
Copy link to clipboard
Copied
On the command-line, you would run it like this:
> java -cp C:\ColdFusion10\cfusion\wwwroot\ReaderRFID\lib\AlienRFID.jar AlienClass1ReaderTest
One way to translate this into Coldfusion is:
<cfexecute name="java" arguments="-cp C:\ColdFusion10\cfusion\wwwroot\ReaderRFID\lib\AlienRFID.jar AlienClass1ReaderTest" outputFile="#expandpath('output.txt')#" ></cfexecute>
Java done.
That would run the code and store the output in the current directory as the file output.txt.
Copy link to clipboard
Copied
Thanks!