Barbecue is a free and open source Java library for Barcode generation. This requires the library barbecue-1.5-beta1.jar to be in classpath. The following example shows generating Barcode 2of7.
package com.bethecoder.tutorials.barbecue; import java.io.File; import net.sourceforge.barbecue.Barcode; import net.sourceforge.barbecue.BarcodeFactory; import net.sourceforge.barbecue.BarcodeImageHandler; public class BarCode2of7Test { public static void main (String [] args) throws Exception { //Get Code 2of7 Barcode instance from the Factory Barcode barcode = BarcodeFactory.create2of7("123456"); File imgFile = new File("test2of7.png"); //Write the bar code to PNG file BarcodeImageHandler.savePNG(barcode, imgFile); } }