7 Replies Latest reply: Dec 10, 2014 2:25 PM by djkhalif RSS

    Java class not found

    djkhalif Community Member

      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!

        • 1. Re: Java class not found
          BKBK MVP

          Use <cfset THIS.javaSettings = {LoadPaths = ["/ReaderRFID/lib/AlienClass1ReaderTest.jar"], loadColdFusionClassPath = true, reloadOnChange=false}/>, then instantiate the class, not the JAR.

          • 2. Re: Java class not found
            djkhalif Community Member

            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
              
            • 3. Re: Java class not found
              djkhalif Community Member

              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[i];

                    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!

              • 4. Re: Java class not found
                BKBK MVP

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

                • 5. Re: Java class not found
                  djkhalif Community Member

                  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[i];

                        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
                  • 6. Re: Java class not found
                    BKBK MVP

                    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.

                    • 7. Re: Java class not found
                      djkhalif Community Member

                      Thanks!