Apache Tomcat Streaming Barcode Generator Integration Tutorial
IDAutomation's Java Servlets function as a streaming barcode generator which can be easily utilized within several applications. This tutorial will demonstrate how to implement streaming barcodes with the Apache Tomcat application server using IDAutomation's Java Servlets.
Buy License Download Demo Support
Configuring Apache Tomcat to Run Java Servlets
Java Servlets are used to add barcode support to a dedicated web server. IDAutomation's Servlet is compatible with all browsers and is easy to embed in HTML as an image with the <IMG> tag. These Java Servlets can be hosted on a client's server and easily streamed to the desired application. The latest release of the Java Barcode Component is compiled with Java 17 and is compatible with Tomcat 10.1 and later versions. If using an older version of Tomcat or Java, refer to the legacy folder in the Java Package available upon download. This tutorial will focus on the newest 2024 release. A separate section will cover the legacy method for those using older configurations.
QRCode Servlet Barcode Example:
- Install or verify the use of Java (JDK or JRE) 17 or above. When possible, IDAutomation recommends installing the latest version of Java that is available.
- Special requirements for Linux and Unix servers:
- Be sure Java.awt GUI functions are available in the environment. This is not usually an issue with Windows® servers. In Unix or Linux, if the Java environment has the java.awt library is stripped out, the Java products will not be able to generate images.
- If the server does not have an X-Window environment, either (1) use Headless Java or (2) connect to a remote X Server or (3) install the X Windows environment and run an X Windows session or (4) install an emulator, PJA library or virtual frame buffer as described in the XWindow Error Document.
- Download the demo or purchase the necessary IDAutomation Java Barcode Package and set the CLASSPATH environment variable to include all JAR files that need to be implemented. For example:
CLASSPATH =C:\Program Files\Apache Software Foundation\Tomcat 10.1\lib\servlet-api.jar;C:\path\to\IDAQRCode.jar - Install Apache Tomcat according to the instructions and set up the required environment variables. In this example the following environment variables are set:
CATALINA_HOME = C:\Program Files\Apache Software Foundation\Tomcat 10.1
JAVA_HOME = C:\Program Files\Java\jdk-17 - Verify Apache Tomcat installation from a browser by opening http://localhost:8080/; if it does not open refer to the Apache Tomcat documentation for support.
- Place the IDAQRCode.jar file in the /WEB-INF/lib directory of the appropriate WebApp. Since this example will use the root WebApp, the file is placed in "C:\Program Files\Apache Software Foundation\Tomcat 10.1\webapps\ROOT\WEB-INF\lib". If the lib folder does not exist it will need to be created.
- Edit the web.xml in the appropriate /WEB-INF/ directory for the WebApp. Insert the following lines in the Servlet Mappings section before </web-app> to map a servlet-class to a URL:
<servlet> <servlet-name>QRCodeServlet</servlet-name> <servlet-class> com.idautomation.qrcode.IDAutomationServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>QRCodeServlet</servlet-name> <url-pattern>/servlet/QRCodeServlet</url-pattern> </servlet-mapping>
- Restart the Apache Tomcat server by either restarting the service or executing the appropriate control scripts per system configuration. In this example, shutdown.bat and startup.bat are executed from "C:\apache-tomcat-10.1\bin".
- After the servlet server is started, specify the appropriate URL that matches the url-pattern specified in web.xml above with any necessary parameters to stream the barcode image. The following generates a barcode encoding "IDAutomation Servlet Demo":
http://localhost:8080/servlet/QRCodeServlet?D=IDAutomation%20Servlet%20Demo&W=300&H=300 - For convenience, the other barcode types that might be needed for the web.xml file are provided below:
<servlet>
<servlet-name>QRCodeServlet</servlet-name>
<servlet-class>com.idautomation.qrcode.IDAutomationServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>AztecServlet</servlet-name>
<servlet-class>com.idautomation.aztec.IDAutomationServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DataBarServlet</servlet-name>
<servlet-class>com.idautomation.databar.IDAutomationServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DataMatrixServlet</servlet-name>
<servlet-class>com.idautomation.datamatrix.IDAutomationServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DotCodeServlet</servlet-name>
<servlet-class>com.idautomation.dotcode.IDAutomationServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>MaxiCodeServlet</servlet-name>
<servlet-class>com.idautomation.maxicode.IDAutomationServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>PDF417Servlet</servlet-name>
<servlet-class>com.idautomation.pdf417.IDAutomationServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>LinearServlet</servlet-name>
<servlet-class>com.idautomation.linear.IDAutomationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>QRCodeServlet</servlet-name>
<url-pattern>/servlet/QRCodeServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AztecServlet</servlet-name>
<url-pattern>/servlet/AztecServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DataBarServlet</servlet-name>
<url-pattern>/servlet/DataBarServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DataMatrixServlet</servlet-name>
<url-pattern>/servlet/DataMatrixServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DotCodeServlet</servlet-name>
<url-pattern>/servlet/DotCodeServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MaxiCodeServlet</servlet-name>
<url-pattern>/servlet/MaxiCodeServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>PDF417Servlet</servlet-name>
<url-pattern>/servlet/PDF417Servlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LinearServlet</servlet-name>
<url-pattern>/servlet/LinearServlet</url-pattern>
</servlet-mapping>
Linear Servlet Barcode Example (Legacy):
- Install or verify the use of Java (JDK or JRE) 1.2 or above. The encoder requires Java 1.2 or above to generate the image files used by the servlet. When possible, IDAutomation recommends installing the latest version of Java that is available.
- Special requirements for Linux and Unix servers:
- Be sure Java.awt GUI functions are available in the environment. This is not usually an issue with Windows® servers. In Unix or Linux, if the Java environment has the java.awt library is stripped out, the Java products will not be able to generate images.
- If the server does not have an X-Window environment, either (1) use Headless Java or (2) connect to a remote X Server or (3) install the X Windows environment and run an X Windows session or (4) install an emulator, PJA library or virtual frame buffer as described in the XWindow Error Document.
- Download the
demo
or purchase the necessary IDAutomation Java Barcode Package and set the
CLASSPATH environment variable to include all JAR files that need to be
implemented. For example:
CLASSPATH = C:\Program Files (x86)\Java\jre1.8.0_66\bin;C:\apache-tomcat-8.0.32\bin;C:\IDAutomationJava\LinearBarCode.jar - Install Apache Tomcat according to the instructions and set up the required environment variables. In this example the following environment
variables are set:
CATALINA_HOME = C:\apache-tomcat-8.0.32
JRE_HOME = C:\Program Files (x86)\Java\jre1.8.0_66 - Verify Apache Tomcat installation from a browser by opening
http://localhost:8080/; if it does not open refer to the Apache Tomcat documentation for support.
- Place the LinearBarCode.jar file in the /WEB-INF/lib directory of the appropriate WebApp. Since this example will use the root WebApp, the file is placed in "C:\apache-tomcat-8.0.32\webapps\ROOT\WEB-INF\lib". If the lib folder does not exist it will need to be created.
- Edit the web.xml in the appropriate /WEB-INF/ directory for
the WebApp. Insert the following lines in the Servlet Mappings section before
</web-app> to map a
servlet-class to a URL:
<servlet> <servlet-name>LinearServlet</servlet-name> <servlet-class> com.idautomation.linear.IDAutomationServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>LinearServlet</servlet-name> <url-pattern>/servlet/LinearServlet</url-pattern> </servlet-mapping>
- Restart the Apache Tomcat server by either restarting the service or executing the appropriate control scripts per system configuration. In this example, shutdown.bat and startup.bat are executed from "C:\apache-tomcat-8.0.32\bin".
- After the servlet server is started, specify the appropriate URL that
matches the url-pattern specified in web.xml above with any necessary parameters to stream the barcode image.
The following generates a barcode encoding "123456789012":
http://localhost:8080/servlet/LinearServlet?BARCODE=123456789012&EM=.06
- Once the servlet is working it may be integrated into any compatible application or included in HTML as a dynamic URL.
2D Data Matrix Servlet Example:
- Perform the steps above for the linear installation and verify that works properly.
- Place the appropriate jar file in the /WEB-INF/lib directory of the appropriate WebApp as described in step 6 above. This example uses the IDADataMatrix.jar file.
- Modify web.xml as described in step 7 above to include the additional
servlet-name, servlet-class, and url-pattern of the jar file:
<servlet> <servlet-name>LinearServlet</servlet-name> <servlet-class> com.idautomation.linear.IDAutomationServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>LinearServlet</servlet-name> <url-pattern>/servlet/LinearServlet</url-pattern> </servlet-mapping> <servlet> <servlet-name>DataMatrixServlet</servlet-name> <servlet-class> com.idautomation.datamatrix.IDAutomationServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>DataMatrixServlet</servlet-name> <url-pattern>/servlet/DataMatrixServlet</url-pattern> </servlet-mapping>
- Restart the Apache Tomcat according to step 8 above.
- Open the appropriate URL that matches the url-pattern specified in web.xml
with any necessary parameters to stream the barcode image.
http://localhost:8080/servlet/DataMatrixServlet?D=IDAutomation%20Servlet%20Demo&X=.3 - Other barcode types may also be implemented in the same way by specifying the appropriate servlet-class in web.xml.