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