Java POS从命令提示符发出,尽管从NetBeans正常工作

时间:2016-12-23 12:18:00

标签: java netbeans javapos

我正在尝试从MS Windows命令提示符执行EPSON提供的带有Java POS ADK的示例程序(使用NetBeans构建为.jar文件)。显示UI屏幕后,我在命令提示符下面出现错误

(点击“打印”按钮后,从NetBeans IDE正常工作并在EPSON TM-T88V打印机上打印) -

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) 

以下是完整的源代码(两个类文件)
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);
    }
}

从命令提示符运行它时所缺少的内容(以管理员权限运行)。还需要其他许可吗?我无法在此特定方案中找到任何文档,例如从NetBeans正常运行但从命令提示符处抛出异常。我在MS Windows 8.1系统上运行它。

1 个答案:

答案 0 :(得分:0)

尝试一下:
安装javaPOS版本。 1.14.6

Windows 10Windows 8.1副本上:

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

来自

  

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

  

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

将lib导入到您的项目中
  

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

运行javaPOS应用程序。