Barcode Xpress for Java v14.0 - Updated
Getting Started / Try the Sample Application
In This Topic
    Try the Sample Application
    In This Topic

    Introduction

    We offer two ways to try out Barcode Xpress samples. The 'Hello Barcode Xpress for Java' sample is hosted on GitHub and the ReadBarcodes sample is provided with Barcode Xpress for Java in the Samples folder.

    Hello Barcode Xpress for Java

    The Hello Barcode Xpress for Java is a simple barcode reading sample hosted on GitHub to demonstrate how easy it is to read barcodes from your images with Barcode Xpress.

    Read Barcodes

    The ReadBarcodes sample is located in the "samples" sub-folder located at samples. It also contains the ReadMe.txt file with detailed instructions on how to build and run the samples.

    Please refer to the Build and Run Samples section below for information on building the sample.

    Barcode Xpress for Java has the following sample to get you started:

    • ReadBarcodes - Recognizes the text in an image(s) and prints results to the console.

    Build and Run Samples

    The commands to compile and run the sample will essentially be the same on both Windows and Linux. The only difference is the punctuation mark used to separate entities on the classpath. Java uses ";" on Windows and ":" on Linux.

    Using Maven

    1. Navigate to the sample folder. For example, for the ReadBarcodes sample use the following command:

      cd samples/ReadBarcodes
      
      
    2. In the sample folder, run the following command:

      mvn clean package dependency:copy-dependencies
      
      

      After the command has successfully completed, the "target" folder will be created in the sample folder.

    3. Run the sample with the following command:

      Linux

      mvn exec:java -Dexec.args="path/to/your/image.bmp"  
      
      

      or

      java -cp "target/ReadBarcodes-1.0.jar:target/dependency/barcodexpressjava-14.0.jar" ReadBarcodes path/to/your/image.bmp
      
      

      Windows

      mvn exec:java -Dexec.args="path/to/your/image.bmp"
      
      

      or

      java -cp "target/ReadBarcodes-1.0.jar;target/dependency/barcodexpressjava-14.0.jar" ReadBarcodes path/to/your/image.bmp
      
      

    Manual Compilation

    1. Navigate to the samples folder. For example, for the ReadBarcodes sample use the following command:

      cd samples/ReadBarcodes
      
      
    2. In the sample folder, compile the sample using the following command:

      Linux

      javac -cp ".:src/main/java:../../bin/barcodexpressjava-14.0.jar" src/main/java/ReadBarcodes.java
      
      

      Windows

      javac -cp ".;src/main/java;../../bin/barcodexpressjava-14.0.jar" src/main/java/ReadBarcodes.java
      
      
    3. Run the sample using the following command:

      Linux

      java -cp ".:src/main/java:../../bin/barcodexpressjava-14.0.jar" ReadBarcodes path/to/your/image.bmp
      
      

      Windows

      java -cp ".;src/main/java;../../bin/barcodexpressjava-14.0.jar" ReadBarcodes path/to/your/image.bmp
      
      

    Running the Sample with Arguments

    The ReadBarcodes sample allows you to specify the type of barcode to search. So, if you want to look for only 1D barcodes, only 2D barcodes, or all types of barcodes, use the type option to specify it.

    Usage

    ReadBarcodes [options] <image1> [<image2> ... <imageN>]
    
    

    Options

    • -t, --type <type> - (optional = true, default = '1d') Barcode types to scan <type>: '1d' - all 1D | '2d' - all 2D | 'all' - all 1D + 2D | you can also specify several barcode types at once
    • -h, --help - (optional = true) Print this help message

    Examples

    ReadBarcodes ../images/Barcode-All-Supported-Types.bmp ../images/Barcode-Multiple-Common.bmp
    
        ReadBarcodes -t 1d -t Planet --type ADD2 ../images/Barcode-All-Supported-Types.bmp
    
        ReadBarcodes -t 2d ../images/Barcode-All-Supported-Types.bmp
    
        ReadBarcodes --type all ../images/Barcode-*
    
    

    Using IntelliJ IDEA

    1. Open IntelliJ IDEA.
    2. Open the folder samples.
    3. Click the build icon in IntelliJ IDEA.
    4. Add a new configuration and select Application.
    5. Name your configuration.
    6. Set the module to the version of Java you're using to compile and run.
    7. Set the classpath to ReadBarcodes.
    8. Set the main class to ReadBarcodes.
    9. Set the program arguments to the path to the image.
    10. Save the configuration and run the sample with the new configuration.

    Configuration Example

    Using Apache NetBeans

    1. Launch Apache NetBeans.

    2. In the File menu, select Open Project...

      NetbeansOpenProject

    3. Navigate to BarcodeXpress13-64/samples. NetBeans should automatically recognize that folder as a Maven Project.

      NetBeans Select Project

    4. Open the Project Properties screen by right-clicking on the project name, ReadBarcodes in the Projects view.

      NetBeans Properties

    5. Navigate to the Run Properties and provide the path to a file in the Arguments field. ../images/Barcode-All-Supported-Types.bmp can be used for a general demonstration:

      NetBeans Arguments

      Click OK to save your changes.

    6. Run the Project. This can be done via the Run menu, Run button in the toolbar, or by right-clicking on the Project and selecting Run. The first time you attempt to run the project, NetBeans will ask for confirmation of which main class you want to run:

      NetBeans Main Class

      Simply press Select Main Class to remember for the duration of the current session, or switch to Remember Permanently if desired.

    7. NetBeans will automatically run Maven to fetch all dependencies and then build and run the ReadBarcodes project. An Output window should be created displaying the results of the build:

      NetBeans Output

    Using Eclipse IDE

    1. Launch Eclipse IDE.

    2. In the File menu, select Open Projects From File Systems...

      Eclipse Open Project

    3. Supply the sample location as Import Source in the Import Projects from File System or Archive dialog and then click Finish:

      Eclipse Import

    4. Open the Project Properties by right-clicking on the project name in the package explorer and selecting Properties. Then, navigate to the Run/Debug Settings page:

      Eclipse Run Settings

    5. Click the New... button and then select Java Application from the list of configurations to create.

    6. In the Main tab of the Edit Configuration dialog, enter ReadBarcodes in the Main class: field:

      Eclipse Main Class

    7. In the Arguments tab of the Edit Configuration dialog, provide an image file path in the Program Arguments: box. You can use ../images/Barcode-All-Supported-Types.bmp for a general demonstration:

      Eclipse Program Arguments

      Then click OK to close the Edit Configuration Dialog and Apply and Close to close the Properties for ReadBarcodes dialog.

    8. You can then run the sample application by clicking on the Run button or by selecting Run from the Run menu. A console pane should appear in Eclipse showing you the output of the sample application:

      Eclipse Output