Skip to main content


Hello World program for a JavaPOS Scale

HelloJavaPOSScale reads the weight from a JavaPOS scale. The latest release of JavaPOS can be downloaded from the Datalogic website here.

The HelloJavaPOSScale repository contains the source and shell scripts to run the HelloJavaPOSScale.jar you build. The repository also has a NetBeans IDE (Integrated Development Environment) project to perform the build. Other IDEs can be used.

Steps to build and run HelloJavaPOSScale.jar:

  1. Install Datalogic JavaPOS. This install includes the JavaPOSTest program.

  2. Make sure Datalogic JavaPOS runs with your scale. With your scale and JavaPOSTest do an Open, Claim, Enable and Read Weight. With nothing on the scale it should read 0.000. Put something on the scale. Press Read Weight again. It should read a positive number.

  3. Clone or download the HelloJavaPOSScale repository.

  4. Build HelloJavaPOSScale.jar. This was originally done with the following. Variations near these should work.

    • Apache NetBeans 11.0
    • Java jdk1.8.0_231
    • The HelloJavaPOSScale project in NetBeans is a Java with Ant, Java Application project. The build uses a library of the JavaPOS's .jar files. These .jar files are in the JavaPOS install's root directory where it has its JavaPOS.jar and its SupportJars directory. Create this library via NetBeans -> Tools -> Libraries. Add the library to the HelloJavaPOSScale NetBeans project via its Properties -> Libraries -> Classpath + -> Add Library...

    Another variation here builds HelloJavaPOSScale.jar without requiring the Apache NetBeans 11.0 Integrated Development Environment (IDE). It instead builds with the included script BuildHelloJavaPOSScale.cmd or These scripts explicitly use the Java JDK's javac and jar programs and require no intermediary IDE. Related "inside" scripts show what is inside HelloJavaPOSScale.jar and Datalogic's JavaPOS.

  5. Update the jpos.xml of your installed JavaPOS to include a <JposEntry logicalName="JavaPOSScaleDevice"> entry for your scale and interface. This entry is a copy of the entry you used with JavaPOSTest above. The only difference is the logicalName is changed to JavaPOSScaleDevice.

  6. With HelloJavaPOSScale.jar make your scale weigh. Use the appropriate HelloJavaPOSScale script: .cmd or .sh. With nothing on the scale it should read 0. With something on the scale it should read a positive integer.

  7. The following images show successful runs at Command Prompts and Terminals.

  8. The non-zero weight runs above do produce a logged error, "ERROR DLSUSBScale - onDataReceived: RESP_NO_WEIGHT" in jposTraceR.log files.

    The reason for the error is because the HelloJavaPOSScale program is so simple that it does not first check for an empty scale with zero weight. This problem is corrected in LiveWeightExample.

    To see the logged error look at the jposTraceR.log and jposTraceR-1.log, jposTraceR-2.log, ,etc. log files. Search for ERROR in the .log file.

    ERROR in jposTraceR.log occurs with non-zero weight run of HelloJavaPOSScale

    The path to the jposTraceR*.log files is found by looking in log4j2.xml in the installed SupportJars subdirectory. The SupportJars directory is expected to be at:

    C:\Program Files\Datalogic\JavaPOS\SupportJars
  9. A Project Run F6 in NetBeans is also successful but it typically requires configuring the Working Directory in Project Properties -> Run.

    NetBeans - Run Project F6

    Set the Working Directory to the JavaPOS install directory:

    C:\Program Files\Datalogic\JavaPOS

    You need to configure the working directory and java.library.path to VM options at NetBeans -> Project Properties -> Run.

    NetBeans - Project Properties - Run - need to set Working Directory