Code
You can download the project for this lesson.
You can also copy the code used in the video here:
In
pom.xml file:
<dependency>
<groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-bridge</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.0</version>
</dependency>
Transcription
Hello, I'm Mónica. In this lesson, you'll learn how to generate barcodes
and QR codes in a report using information sent from OpenXava.
Continuing with the report from the last lesson, we drag a barcode
element into the report. From all the available options, we choose EAN13
from Barcode4J. In the barcode properties panel, we can assign an
expression. We'll use the ISBN parameter. We save, copy, and start the
application. After waiting a while, the report isn't generated. We check
the OpenXava Studio console and see an error. It says it can't find a
class from the Barcode4J library. We copy the stack trace and paste it
into a search engine. Here, we find a solution: adding a dependency in
the pom.xml file located at the root of the project. We copy the
dependency and paste it into the pom. We save and run a Maven install
before starting the application again. We try generating the report
again. The report is generated but incomplete, so we check the console
to see the error this time. It also says it can't find a class. We do
the same thing, searching online. Here it says the solution is to add
another dependency. We paste it into the pom and run Maven install
before starting the application again. This time it works. Here's the
result: the element generates a barcode from the 13 digits of the ISBN
it receives.
Let's try another one. This time we'll select QRCode and assign it the
ISBN parameter. We save, copy, and test the report. It tells us it can't
find a class. We copy the stack trace into the search engine to see if
we can find a solution. It seems we're missing these two dependencies.
We add them to our pom. We save and run Maven install before restarting
the application. There it is, the QRCode. If we scan it, it will display
its information, which is the ISBN.
In this lesson, you've seen two types of barcodes: EAN13 and QRCode.
There are other types of barcodes, each with a specific design to meet
the needs of its particular field. We encourage you to try the other
types. If you have any questions or problems, you can ask in the forum,
or download the code from this lesson via the repository link—both links
are in the video description. Goodbye!