java.lang.NoClassDefFoundError: jpos/JposException

Questions and answers on developing, deploying and using plugins and JavaBeans

java.lang.NoClassDefFoundError: jpos/JposException

Postby DeRRudi » Tue Dec 13, 2005 11:46 am

Hi all,

I've created a plugin for servoy. The IScriptObject of the plugin now contains 2 methods, the first just a simple return string. to test if it works correctly. (and it does) the second is an boolean. In this boolean i create a instance of an other class. This class should communicate with a JPos Printer and print a reciept for me.
If i run the code seperately from my plugin it works. (calls the printer and prints my reciept) But now its loaded into the plugin i get the next error:

java.lang.NoClassDefFoundError: jpos/JposException


The code to create the instance:
Code: Select all
public boolean js_printReciept()
{
   PrinterClass printer = new PrinterClass();
   return printer.printReciept();   
}


The PrinterClass:
Code: Select all
public class PrinterClass
{
   //instantiate a new jpos.POSPrinter object   
   private static POSPrinter printer;
   private static String ESC, LF, SPACES;
   
   
   public static void main(String args[])
   {   
      /*
          If you want to place the jpos.xml file elsewhere on your local file system then uncomment the
          following line and specify the full path to jpos.xml.
      
          If you want to place the jpos.xml file on a webserver for access over the internet then uncomment
          the second System.setProperty line below and specify the full URL to jpos.xml.
      */
      System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "c:\\jpos.xml");
      //System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_URL_PROP_NAME, "http://some-where-remote.com/jpos.xml");
      
      printer = new POSPrinter();
      // constants defined for convience sake (could be inlined)
      ESC    = ((char) 0x1b) + "";
      LF     = ((char) 0x0a) + "";
      SPACES = "                                                                      ";   
   }
   
   public boolean printReciept()
   {
      try
         {
             // open the printer object according to the entry names defined in jpos.xml
             printer.open("Star TSP100 Cutter (TSP143)_1");
      
             // claim exclsive usage of the printer object
             printer.claim(1);
             
             // enable the device for input and output
             printer.setDeviceEnabled(true);
             
             // set map mode to metric - all dimensions specified in 1/100mm units
             printer.setMapMode(POSPrinterConst.PTR_MM_METRIC);  // unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units
             
             do
             {
                 // poll for printer status
                 //   a javax.swing based application would be best to both poll for status
                 //   AND register for asynchronous StatusUpdateEvent notification
                 //   see the JavaPOS specification for details on this
                 
                 // check if the cover is open
                 if (printer.getCoverOpen() == true)
                 {
                     System.out.println("printer.getCoverOpen() == true");
                     
                     // cover open so do not attempt printing
                     break;
                 }
                 
                 // check if the printer is out of paper
                 if (printer.getRecEmpty() == true)
                 {
                     System.out.println("printer.getRecEmpty() == true");
                     
                     // the printer is out of paper so do not attempt printing
                     break;
                 }
                 
                 // being a transaction
                 //   transaction mode causes all output to be buffered
                 //   once transaction mode is terminated, the buffered data is
                 //   outputted to the printer in one shot - increased reliability
                 printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_TRANSACTION);
                 
                 // call printNormal repeatedly to generate out receipt
                 //   the following JavaPOS-POSPrinter control code sequences are used here
                 //   ESC + "|cA"          -> center alignment
                 //   ESC + "|4C"          -> double high double wide character printing
                 //   ESC + "|bC"          -> bold character printing
                 //   ESC + "|uC"          -> underline character printing
                 //   ESC + "|rA"          -> right alignment
                 
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|4C" + ESC + "|bC" + "Star Grocer"     + LF);
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|bC" +               "Shizuoka, Japan" + LF);
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|bC" +               "054-555-5555"    + LF);
      
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|uC" + "Qnty Unit Tx Description" + SPACES.substring(0, printer.getRecLineChars() - "Qnty Unit Tx Description".length()) + LF);
                 
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1  830    Soba Noodles"        + LF);
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1  180    Daikon Radish"       + LF);
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1  350    Shouyu Soy Sauce"    + LF);
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1   80    Negi Green Onions"   + LF);
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   1  100    Wasabi Horse Radish" + LF);
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,               "   2  200 Tx Hashi Chop Sticks"   + LF);
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, LF);
                 
             
                 
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|4C" + ESC + "|bC" + "Thank you" + LF);
      
                 // the ESC + "|100fP" control code causes the printer to execute a paper cut
                 //   after feeding to the cutter position
                 printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|100fP");
      
                 // terminate the transaction causing all of the above buffered data to be sent to the printer
                 printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_NORMAL);
                 
                 // exit our printing loop
                 return true;
             } while (false);
         }
         catch(JposException e)
         {
             // display any errors that come up
             e.printStackTrace();
             return false;
         }
         finally
         {
             // close the printer object
             try
             {
                 printer.close();
             }
             catch (Exception e) {}
         }
         return true;
         //System.out.println("StarReceiptTest finished.");
         //System.exit(0);
   }
}




It looks like it has something to do with the classpath settings? but i believe they are set correctly.
Anybody has any ideas?

Greetz Rudi
DeRRudi
 
Posts: 14
Joined: Tue Dec 13, 2005 11:35 am

Print java.class.path

Postby XFox » Tue Dec 13, 2005 12:31 pm

Why don't you print the java.class.path property value to see if the jpos package is in the classpath?
Place this code in the inizialize() method of the plugin class that implements IClientPlugin:

Code: Select all
System.out.println("java.class.path = " + System.getProperty("java.class.path"));


Maybe you could try to set the classpath with a call to System.setProperty(String key, String value), but I'm not sure if this would have effect.
User avatar
XFox
 
Posts: 32
Joined: Fri Apr 22, 2005 12:52 pm
Location: Italy

Postby IT2Be » Tue Dec 13, 2005 12:41 pm

Is this from the client or the developer that you get the classpath error?

You say when you run it seperately it works. Where do you set your classpath and what are your settings?

What happens when you throw your class into the plugins dir of the servoy root?
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby DeRRudi » Tue Dec 13, 2005 1:08 pm

ok.. solved the error.. i placed the jar's with the jpos drivers in the servoy plugin directory and reloaded the classpath external jar.

thnx for your help!

Greetz
DeRRudi
 
Posts: 14
Joined: Tue Dec 13, 2005 11:35 am

Postby DeRRudi » Thu Dec 22, 2005 3:37 pm

I ran into another problem.

I've managed to call the printer from the client. Therefore i've loaded the jpos.xml file needed for the printer settings into the plugin jar file.
When i open the client on the computer where the developer is running and with the printer installed it works properly.
but if i install the printer on another computer, then open the client, it gives an error (error during executing myMethod). Is'nt it possible to read the xml file on another computer? or is there something else going wrong?

Greetz Rudi
DeRRudi
 
Posts: 14
Joined: Tue Dec 13, 2005 11:35 am


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 3 guests