JavaPOS Hello World in Java

10,406

Well, I finally found it myself. It seems like you need a part of the program from JavaPOS (that part only has interfaces and abstract classes) and you need the library from the manufacturer of the device. The jpos.xml is generated after the printer is installed. A software (also provided by the manufacturer) generates entries in the jpos.xml file based on the name of the printer and other settings. You must include this file in your program.

Finally, the following code makes the connection to the printer :

POSPrinter printer = new POSPrinter();
// open the printer object according to the entry names defined in jpos.xml
printer.open("printerName");

The method printnormal() is then used to print. If you printing asynchonously, you also need transactionPrint() to empty the buffer.

Share:
10,406

Related videos on Youtube

Philippe Carriere
Author by

Philippe Carriere

Software Developer Gamer Geek

Updated on April 14, 2022

Comments

  • Philippe Carriere
    Philippe Carriere about 2 years

    I would like to print a sample line on my USB POS (Point-Of-Sale) printer from a java program on Windows XP.

    I tried to setup a JavaPOS implementation but I get exception after exception for a missing jpos.xml or missing javax.usb.properties file.

    Can anyone tell me how to generate those files? They somewhat need to link to an implementation or something like that and I'm not sure what the (rare, unclear and incomplete) documentation means. Any other help would be appreciated.

    My current printer model is Star TSP 100 with a USB connector. My printer seems to be connected correctly since I can print a file on it from windows.

  • Philippe Carriere
    Philippe Carriere over 14 years
    I hope this will save someone else a few hours of research.
  • Ozzy
    Ozzy about 12 years
    thanks... didn't realise the jpos.xml file had to be generated from the star config utility until i read your answer. For those of you who can't find it... you need to open your Star Config Utility in Star Line Mode, click JavaPOS on the left side, press "Create JavaPOS XML Registry File", then click Add New for your printer and cash drawer, then click Apply - the jpos.xml file will be automatically updated. Finally replace [Device].open("default") to the Logical Name written in the jpos.xml file.
  • Chetan Pulate
    Chetan Pulate over 9 years
    Hey Philippe could you share the JavaPos Hello world program i am a newbie trying to print a reciept in my app using a pos printer. Your program would be very helpful buddy
  • Philippe Carriere
    Philippe Carriere over 9 years
    This was almost 5 years ago, I don't have the code anymore. But from what I can recall, this answer contains most of what is needed. POSPrinter printer = new POSPrinter(); printer.open("printerName"); printer.printnormal("Hello World"); printer.transactionPrint(); If you configured your jpos.xml correctly, it should work.