EDIT: I found out that we had a module kicking around in some demo projects that generates barcodes. It was last updated for Mendix 5.14: download it here.
I see three approaches for this: use either a Java library, a web service, or a custom font to generate a barcode (Thanks Kilian!)
I have positive experience with free code 39 fonts. This way you don't have to generate anything. Just make sure the correct font it used and it is rendered as a barcode.
You can download one from http://www.free-barcode-font.com/. Note that this will only create code 39 barcodes.
I always had issues with free fonts or web services and ended up using this one:
http://www.java4less.com/barcodes/barcodes.php?info=BarcodesWebServices_Guide
It's not free, but has worked very well for me.
I would offload this to the client if possible:
http://lindell.me/JsBarcode/