Containerize LEADTOOLS Applications with Docker and Maven - Java

This tutorial shows how to set up a Java Console application with Maven using the LEADTOOLS SDK in a Docker container.

Summary This tutorial covers how to Containerize a Java Console Application using LEADTOOLS with Maven and Docker.
Completion Time 30 minutes
Platform Java Console Application with Maven using Docker
IDE Eclipse
Development License Download LEADTOOLS

Required Knowledge

Before working on the Containerize LEADTOOLS Applications with Docker and Maven - Java tutorial, ensure that you install the LEADTOOLS SDK as well as Docker for Desktop. If you do not have both downloaded, use the below links to access the respective installers.

Prepare Project for use with Docker


Since the Java project is using Maven, be sure to move your package and main class under \src\main\java\<PROJECT_NAME>\, or else Maven will not be able to locate it upon execution in the Docker container.

Create a folder called lead in the same directory that contains the Java project's src folder. Inside the lead folder create another folder called src. Add all the LEADTOOLS JAR files required by the application to this new src folder. Create a new file called pom.xml in the same src directory.

Add the following code to the pom.xml file.

<project xmlns="" xmlns:xsi="" 

Add the below code to the pom.xml file to determine version variables for later code and set the compiler version needed for proper building.


Next, you need to define each of the LEADTOOLS JAR files added to the program as a dependency. Notice ${version.leadtools}, this pulls the value from the variable we set above. A <dependency></dependency> block and <execution></execution> block will need to be added for each LEADTOOLS JAR in the project.

                    <!-- Leadtools Jar --> 

This final section instructs Maven to make the generated JAR file runnable so docker can execute it. Change the <mainClass></mainClass> block to match the program's package name and main class.

            <!-- Builds Runnable Application Jar --> 

Create the Docker File

In the same directory as the pom.xml file, create a new file named Dockerfile. This file will contain all the instructions for Docker to build the container. The Dockerfile instructs Docker to install the required dependencies within the container so that everything functions correctly.

Setup Project Files

This section of the Dockerfile will setup the project files to run in the container. First, it installs the SDK required by the application (change to match accordingly, information found at

Next it sets the container's current directory to /app and copies the files needed by Maven in the local target directory to the containers app directory. Run Maven to build the JAR File.

### Building the project ( 
FROM maven:3.6-openjdk-17-slim AS build-env 
# Copy files needed by Maven to container 
COPY /src /app/src 
COPY /lead /app/lead 
COPY pom.xml /app/pom.xml 
# Build JAR File 
RUN mvn initialize 
RUN mvn -f /app/pom.xml clean install 

Setup Runtime Environment

This next section of the Dockerfile will setup the runtime environment in the container.

First, it installs the runtime required by the application (change to match accordingly, info found at and sets the container's current directory to Temp. It then sets a container environment DEBIAN_FRONTEND to non-interactive to prevent any confirmations or optional inputs to be requested by installing dependencies. Finally, it updates the apt-get and installs the apt-utils and wget to further facilitate installing the other dependencies.

### Building the runtime image ( 
FROM debian:sid 
WORKDIR /temp 
# Generate the APT cache 
ENV DEBIAN_FRONTEND noninteractive 
RUN apt-get update \ 
    && apt-get install -y apt-utils wget 

Install Java and Set Environment Variables

In order to run Java applications in this Docker container, we need to install Java and set Environment Variables to access Java commands.

Use wget to instruct the container to download the JDK required for installation (adjust link to match the JDK your application is made in). Use apt-get to instruct the container to install the files to it.

The ENV lines set the environment variables to tell the container how to use Java commands. The RUN command confirms Java is installed and the container understands Java commands and updates the apt-get.

# Install Java 
RUN wget 
RUN apt-get install -y --no-install-recommends openjdk-15-jdk 
ENV JAVA_HOME=/usr/lib/jvm/openjdk-15-jdk 
RUN java --version 
# Update APT cache 
RUN apt-get update 

Setup LEADTOOLS Dependencies

This section installs the dependencies needed by LEADTOOLS in order to run in the container.

The Microsoft fonts section is only needed for applications with a GUI. The wkhtmltopdf section is needed to process HTML and provide dependencies in license processing.

# Install the LEAD dependencies ( 
RUN apt-get install -y \ 
    uuid-dev uuid-runtime gcc g++ libc-dev-bin \ 
    linux-libc-dev libx11-6 libx11-dev libxt6 \ 
    libxt-dev sqlite3 libsqlite3-dev libfreetype6 
# Install Microsoft fonts ( 
#RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections 
#RUN apt-get install -y \ 
#    fontconfig ttf-mscorefonts-installer 
# Install wkhtmltopdf ( 
RUN wget -q 
RUN apt install -y --allow-unauthenticated \ 
RUN ldconfig 

Final Setup

In this final section we do final clean up, final setup, and specify how to initialize the application.

Set the containers current directory to app and remove the Temp directory we made as it is no longer needed. If your application is a web-based application, uncomment out EXPOSE 80 so your application will listen on Port 80, change port number as needed. Next, the contents of the app directory in the container that was stored in the buid-env section is pasted to the app folder. Lastly, we set the command java -jar app.jar to run when we start the container which triggers the application to run.

# Delete the temp files 
RUN rm -rf /temp 
# Copy and deploy application 
COPY --from=build-env /app ./ 
COPY --from=build-env /app/target/App-1.0-jar-with-dependencies.jar ./app.jar 
ENTRYPOINT ["java", "-jar", "app.jar"] 

Run the Project

Build the Docker Container

Open the Command Prompt/Terminal or Windows PowerShell and navigate to your project folder that contains the Dockerfile using the below command.

cd '<PathToProject>' 

Build and name the container <project_name> all in lower case format and single word using the script below:

docker build -t <project_name> . 

It may take a few minutes for Docker to complete. Once completed, the image can then be run.

Run the Docker Container

Once the Docker image is built, use the following command to run the container:

docker run <project_name> 

Docker Run Commands

If your application needs user input, you need to run this command to allow interaction:

docker run -i <project_name> 

If your application needs import/export files, you can direct it to a local directory via this command:

docker run -v /c/temp:/app/data <project_name> 

This will map the local C:\Temp folder to the container's /app/data folder.


This tutorial showed how to containerize a Java application in a Docker Container.

See Also

Help Version 21.0.2023.3.1
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.