Java POS issues from command prompt, although working properly from NetBeans

857 views Asked by At

I am trying to execute a sample program (built as .jar file using NetBeans) provided by EPSON with Java POS ADK, from MS Windows command prompt. After showing the UI screen, I am getting below error at command prompt

(From NetBeans IDE it is working properly and printing on EPSON TM-T88V printer when clicked on Print button ) -

jpos.JposException: Could not create an instance.
        at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.createComm
Instance(CommonPrinterService.java:2891)
        at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.open(Commo
nPrinterService.java:1311)
        at jpos.BaseJposControl.open(Unknown Source)
        at helloworldapp.Step1Frame.processWindowEvent(Step1Frame.java:81)
        at java.awt.Window.processEvent(Window.java:2013)
        at java.awt.Component.dispatchEventImpl(Component.java:4889)
        at java.awt.Container.dispatchEventImpl(Container.java:2294)
        at java.awt.Window.dispatchEventImpl(Window.java:2746)
        at java.awt.Component.dispatchEvent(Component.java:4711)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
        at java.awt.EventQueue.access$500(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:709)
        at java.awt.EventQueue$3.run(EventQueue.java:703)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(ProtectionDomain.java:76)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(ProtectionDomain.java:86)
        at java.awt.EventQueue$4.run(EventQueue.java:731)
        at java.awt.EventQueue$4.run(EventQueue.java:729)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:201)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:116)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:105)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 

Below is the complete source code (two class files)
Step1Main.java

package printersample_step1;  

import javax.swing.UIManager;  
import java.awt.*;  

public class Step1Main {  
    /**The application program starts from this point.*/  
    public Step1Main() {  
    Step1Frame frame = new Step1Frame();  
        //For center the window on the display.  
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();  
        Dimension frameSize = frame.getSize();  
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);  
        frame.setVisible(true);  
    }  
    /**The method "Main" */  
    public static void main(String[] args) {  
        try {  
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());  
        }  
        catch(Exception e) {  
            e.printStackTrace();  
        }  
        new Step1Main();  
    }  
}  

Step1Frame.java

/* Step 1  Print as "Hello JavaPOS"*/
//A string is sent by using the method "printNormal", and it is printed.

package printersample_step1;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import jpos.*;


/**
 *  Outline      The code for starting service and the code
 *              for printing are described.
 *  @author     s.muroga
 *  @version    1.00  (2001.04.24)
 */
public class Step1Frame extends JFrame {

    POSPrinterControl114 ptr = (POSPrinterControl114)new POSPrinter();

    JPanel contentPane;
    JPanel jPanel_reciept = new JPanel();
    TitledBorder titledBorder1;
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    GridBagLayout gridBagLayout2 = new GridBagLayout();
    JButton jButton_Print = new JButton();

    /**Constract "Frame"*/
    public Step1Frame() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
            jbInit();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

    /**Form the component*/
    private void jbInit() throws Exception  {
        //setIconImage(Toolkit.getDefaultToolkit().createImage(Step1Frame.class.getResource("[Your Icon]")));
        contentPane = (JPanel) this.getContentPane();
        titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(134, 134, 134)),"Receipt");
        contentPane.setLayout(gridBagLayout1);
        this.setSize(new Dimension(300, 180));
        this.setTitle("Step 1  Print \"Hello JavaPOS\"");
        jPanel_reciept.setLayout(gridBagLayout2);
        jPanel_reciept.setBorder(titledBorder1);
        jButton_Print.setText("Print");
        jButton_Print.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                jButton_Print_actionPerformed(e);
            }
        });
        contentPane.add(jPanel_reciept, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(15, 0, 0, 0), 20, 20));
        jPanel_reciept.add(jButton_Print, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 10, 5, 10), 130, 0));
    }

    /**
     * Outline     The processing code required in order to enable
     *            or to disable use of service is written here.
     * @exception JposException  This exception is fired toward the failure of
     *                          the method which JavaPOS defines.
     */
    /**When the window was closed*/
    protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            this.closing();
        }
        /**When the window open*/
        else if (e.getID() == WindowEvent.WINDOW_OPENED) {
            // JavaPOS's code for Step1
            try {
                //Open the device.
                //Use the name of the device that connected with your computer.
                ptr.open("POSPrinter");

                //Get the exclusive control right for the opened device.
                //Then the device is disable from other application.
                ptr.claim(1000);

                //Enable the device.
                ptr.setDeviceEnabled(true);
            }
            catch(JposException ex) {
            }
        }
        // JavaPOS's code for Step1--END
    }

    //***********************Button*************************************************
    /**
     * Outline      The code for using the most standard method "PrintNormal"
     *             to print is described.
     */
    void jButton_Print_actionPerformed(ActionEvent e) {
        // JavaPOS's code for Step1
        try{
            //printNormal(int station, String data)
            //A string is sent by using the method "printNormal", and it is printed.
            // "\n" is the standard code for starting a new line.
            // When the end of the line have no "\n",printing by
            //  using the method "printNormal" doesn't start, may be.
            ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT,"Hello JavaPOS\n");
        }
        catch(JposException ex){
        }
        // JavaPOS's code for Step1--END
    }

    //***********************Method*************************************************
    /**
     * Outline     The code to finish a service.
     */
    void closing(){
        // JavaPOS's code for Step1
        try{
            //Cancel the device.
            ptr.setDeviceEnabled(false);

            //Release the device exclusive control right.
            ptr.release();

            //Finish using the device.
            ptr.close();
        }
        catch(JposException ex){
        }
        // JavaPOS's code for Step1--END
        System.exit(0);
    }
}

What I am missing when running it from command prompt (running with Administrator rights). Any other permission required ? I could not find any documentation in this particular scenario, like running properly from NetBeans but throwing an exception from command prompt. I am running it on MS Windows 8.1 system.

1

There are 1 answers

0
Tabi On

Try this:
Install javaPOS ver. 1.14.6

On Windows 10 or Windows 8.1 copy:

  1. BluetoothIO.DLL
  2. epsonjpos.dll
  3. EthernetIO31.DLL
  4. SerialIO31.dll
  5. USBIO31.DLL

from

C:\Program Files\EPSON\JavaPOS\bin\

to

C:\Program Files\Java\jre1.8.0.171\bin\

Import lib to your project from

C:\Program Files\EPSON\JavaPOS\lib\

Run javaPOS application.