Using ZXing with Codenvy

Zebra Crossing (ZXing) is an awesome open source library that one can use to generate / parse QR Codes in almost all the platforms (Android, JavaSE, IPhone, RIM, Symbian etc). QRGen is a good library that creates a layer on top of ZXing and makes QR Code generation in Java a piece of cake. It has a dependency on ZXing, so you would need ZXing jar files along with QRGen to create QR Codes in Java.

On the download page of ZXing, you will not find the JAR files. Instead we have to create JAR files using the source code. (for non-maven users)

Create a Project

Login to your Codenvy workspace and create a new WAR Project say “serveQR”. Project file structure is shown below :

Create pom.xml and Add Dependencies

Specify the below dependencies in pom.xml which are prerequisite for the generating the required QR code. Make sure these jars are included under Maven Dependencies.

  • qrgen-1.3.jar
  • Javaee-web-api-6.0.jar

Pom.xml :


<name>Maven Repository Switchboard</name>
<name>Repository hosting the jee6 artifacts</name>

Create Java Class

This servlet makes use of the qrgen.jar to process the given text through index.jsp and generates the QR code and also responsible for presenting the QR code as an Image.

Code Logic :

String qrtext = request.getParameter("txt");
			ByteArrayOutputStream out = QRCode.from(qrtext).to(ImageType.PNG).stream();


			OutputStream outStream = response.getOutputStream();


			PrintWriter pw = response.getWriter();
			pw.write("Required a valid string");

Create index.jsp

Index jsp acts as an interface to input the text for which a QR Code would be generated by calling the servlet QRCodeGenServlet class .

Create QR Code using zxing
<form action="qrGen" method="get">
<p>Enter Text to generate QR Code</p>
<input type="text" name="txt" /><br/>
<input type="submit" value="Generate"/>


Create web.xml and success.jsp

We are mapping the index.jsp file to the earlier created servlet class in this web.xml file and the action will load the QR Image:

Web.xml :



Build and Run the Application

Upon successful building the application and executing, it loads index.jsp where we input a text, then it will be successfully generates a QR Code and will presented with the QR Image.