Open Barcode for Java
A Maven artifact compiled to Java 8 bytecode, with JUnit 5 tests as a test-scoped dependency.
Install
<dependency>
<groupId>dev.openbarcode</groupId>
<artifactId>openbarcode</artifactId>
<version>2.0.0</version>
</dependency>Generate a barcode
import com.floms.openbarcode.linear.UPC;
int[] bars = new UPC("03600029145").barcode(); // 95 modulesThe example encodes UPC-A 03600029145, which gets check digit 2 and produces 95 modules. The same input gives the same modules in every Open Barcode library.
More examples
Each example uses the same modules as the tests, so the output matches the other languages.
import com.floms.openbarcode.linear.*;
int[] upc = new UPC("03600029145").barcode(); // 95 modules
int[] ean = new EAN("400638133393").barcode(); // 95 modules
int[] code39 = new Code39("CODE39").barcode(); // 103 modulesimport com.floms.openbarcode.linear.UPC;
try {
new UPC("036000291453"); // the check digit should be 2
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}Source and tests
The source, tests and release workflow are in the Java repository on GitHub.