Ive been researching the ins and outs of javaPOS, JCL, JDK, paths and classpaths for a while now trying to figure out how i can successfully print a line on my Epson TM-T20 Receipt printer using JavaPOS. Since the javaPOS installation from the disc (that came with the printer) will not install correctly on Windows 10 (thinks its installing on Linux), I need to create my own jpos.xml file. It needs to contain device entries for my printer. (I have also tried a fresh JavaPOS ADK download from Epson and also an older version without success).
This is my setup so far....
- I have extracted the latest JCL. Instead of setting classpath to JCL binary files (jar files), Ive placed them in the java ext directory.
- I extracted the Java "src.zip" located in JDK1.8.0_74 into the JDK1.8.0_74 directory as "src".
- I have placed the "jpos" folder containing all the jpos source files into that "src" folder, so I can easily import them into my test application.
- I have studied other jpos.xml (including POSTest/2 & Starmicronics eg.) to get an idea of what entries mine needs to contain.
- Ive placed my jpos.xml in the Java "src" folder.
Here is my jpos.xml....
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE JposEntries PUBLIC "-//JavaPOS//DTD//EN"
"jpos/res/jcl.dtd">
<JposEntries>
<!--Saved by JavaPOS jpos.config/loader (JCL) version 2.3.0-RC3 on 6/03/16 1:20 PM-->
<JposEntry logicalName="TM-T20">
<creation factoryClass="jpos.loader.JposServiceInstanceFactory" serviceClass="jpos.services.POSPrinterService114"/>
<vendor name="Seiko Epson" url="http://www.Epson.com"/>
<jpos category="POSPrinter" version="1.14"/>
<product description="Epson Thermal Receipt Printer TM-T20" name="TM-T20" url="http://www.Epson.com"/>
<!--Other non JavaPOS required property (mostly vendor properties and bus specific properties i.e. RS232 )-->
<prop name="deviceBus" type="String" value="USB"/>
<prop name="portName" type="String" value="ESDPRT001"/>
<prop name="model" type="String" value="TM-T20"/>
</JposEntry>
</JposEntries>
Here is my test application...
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.UIManager;
import jpos.util.JposPropertiesConst;
public class ReceiptPrintMain {
public ReceiptPrintMain() {
ReceiptPrint2 frame = new ReceiptPrint2();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
public static void main(String[] args) {
System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "C:\\Program Files (x86)\\Java\\jdk1.8.0_74\\src\\jpos.xml");
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new ReceiptPrintMain();
}
}
// File: ReceiptPrint2
// Purpose:
import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import jpos.JposException;
import jpos.POSPrinter;
import jpos.POSPrinterConst;
public class ReceiptPrint2 extends JFrame {
POSPrinter ptr = new POSPrinter();
JPanel contentPane;
JPanel jPanel_reciept = new JPanel();
TitledBorder titledBorder1;
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridBagLayout gridBagLayout2 = new GridBagLayout();
JButton jButton_Print = new JButton();
public ReceiptPrint2() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
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));
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
this.closing();
}
else if (e.getID() == WindowEvent.WINDOW_OPENED) {
try {
ptr.open("TM-T20");
ptr.claim(1000);
ptr.setDeviceEnabled(true);
}
catch(JposException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
}
void jButton_Print_actionPerformed(ActionEvent e) {
try{
ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT,"Hello JavaPOS\n");
}
catch(JposException ex){
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
void closing(){
try{
ptr.setDeviceEnabled(false);
ptr.release();
ptr.close();
}
catch(JposException ex){
}
System.exit(0);
}
}
The error message I get is.... "Could not connect to service with logicalName = TM-T20: Exception.message = jpos.loader.jpos.ServiceInstanceFactory.init()"
I'm guessing my jpos.xml file entries are incorrect, mainly factoryClass &/or serviceClass. Please can anyone help me. Perhaps someone has the jpos.xml file created for the TM-T20 and wouldn't mind sharing.