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

Java class not found

Participant ,
Sep 02, 2014 Sep 02, 2014

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!

Views

2.3K

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 Expert , Sep 04, 2014 Sep 04, 2014

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.

Votes

Translate

Translate
Community Expert ,
Sep 03, 2014 Sep 03, 2014

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.

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
Participant ,
Sep 03, 2014 Sep 03, 2014

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
  

Object instantiation exception.

An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. Error: AlienClass1ReaderTest (wrong name: com/alien/enterpriseRFID/examples/AlienClass1ReaderTest).
Resources:
  • Enable Robust Exception Information to provide greater detail about the source of errors. In the Administrator, click Debugging & Logging > Debug Output Settings, and select the Robust Exception Information option.
  • Check the ColdFusion documentation to verify that you are using the correct syntax.
  • Search the Knowledge Base to find a solution to your problem.
Browser  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
Remote Address  192.168.1.202
Referrer 
Date/Time  03-Sep-14 09:34 AM
  

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
Participant ,
Sep 03, 2014 Sep 03, 2014

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!

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 ,
Sep 03, 2014 Sep 03, 2014

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().

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
Participant ,
Sep 04, 2014 Sep 04, 2014

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
  

The main method was not found.

Either there are no methods with the specified method name and argument types or the main method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.
Resources:
  • Enable Robust Exception Information to provide greater detail about the source of errors. In the Administrator, click Debugging & Logging > Debug Output Settings, and select the Robust Exception Information option.
  • Check the ColdFusion documentation to verify that you are using the correct syntax.
  • Search the Knowledge Base to find a solution to your problem.
Browser  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
Remote Address  192.168.2.4
Referrer 
Date/Time  04-Sep-14 01:43 PM

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 ,
Sep 04, 2014 Sep 04, 2014

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.

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
Participant ,
Dec 10, 2014 Dec 10, 2014

Copy link to clipboard

Copied

LATEST

Thanks!

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