How to run Dropwizard Comparison sample using Docker

Reading this article you will understand how to run Dropwizard Comparison sample just in few commands using Docker. After going through this, you will have web application to compare any documents and highlight the identified differences

Dropwizard Comparison Application

Dropwizard Comparison sample is a sample application, that is created with using Dropwizard Framework to familiarize with GroupDocs.Comparison for Java functionality. Despite the fact that it is just a sample, the application is fully functional and can be used to compare any supported file formats. Moreover, thanks to the fact, that sources of the application are available on GitHub, you can easily add needed change the application in any way or add some functions.

System Requirements

To run the sample using Docker you will need to install Docker itself and download Comparison application:

  1. Go to official Docker page and download installer depending on OS
  2. Install Docker according instructions on official Docker page
  3. Open HitHub page with Comparison application and download it’s sources:
    1. Click on green button Code on the top right side of the page
    2. Click Download ZIP link
    3. After download finished, extract the archive to any directory you like

Launching Dropwizard Comparison sample

In order to launch the sample you firstly need to build Docker image. It must be done only once and after that you can use the image to run Docker container whenever you want

Configuring Comparison application

Comparison application has lots of options to be configured. Some of them are available to be changed during each run, but others can be only changed before creating Docker image (in fact, you can update sample by your own to make any option to be configurable after Docker image was created). To change the application configuration you just need to edit configuration.yml file

Building Docker Image of the sample

If want to have any files to be inside Comparison application by default, follow next steps:

  1. Go to \Demos\Dropwizard\ in sample folder
  2. Put files into DocumentSamples directory

Note: of course you can upload files after running the application using it’s interface

To set GroupDocs license:

  1. Go to \Demos\Dropwizard\ in sample folder
  2. Put license file into Licenses directory

To create Docker image for the sample:

  1. Go to \Demos\Dropwizard\ in sample folder
  2. Open console in this directory
  3. Run next command to build an image

That’s actually all. The image is built and added to Docker’s list of images.

Note: groupdocs_comparison_dropwizard_sample in the command is just a name of the image that will be created. You can use any name you want, but don’t forget it, as it will be used to run the application

Running application using prebuilt Image

To run Comparison Dropwizard application you should fallow next steps:

  1. Go to \Demos\Dropwizard\ in sample folder
  2. Open console in this directory
  3. Run next command to run a container with Comparison application

After that, just open link http://localhost:8080/comparison in your favourite browser to see Comparison application

A little details about the command:

  • my-comparer is a name of Docker container, that you can use to stop the application. It can be changed to any other name
  • 8080:8080 means that the application is using port 8080 inside Docker container and Docker connects it to port 8080 outside the container, so that you can use it to access the application in your browser
  • flag --rm means that the container will be deleted automatically by Docker after it will be stopped. The flag can be omitted to keep container after it wil be stopped
  • groupdocs_comparison_dropwizard_sample is a name of an image that we created

To stop the container just run command docker stop my-comparer

Configuring Comparison API

In order to configure application you can use some of predefined environment variables. For example, if you want to disable possibility to download result document, just pass environment variable DOWNLOAD_ON with value false with command of starting container. In this way the command will look like:

There are next predefined variables:

  • LIC_PATH - path to directory with license file
  • DOWNLOAD_ON - enables/disables result file download button in Comparison application UI
  • UPLOAD_ON - enables/disables button to upload files which can be used for comparing (the button is on the left of the open document dialog)
  • PRINT_ON - enables/disables button to print documents
  • FILES_DIR - path to the directory that will be used to store uploaded files
  • RESULT_DIR - path to the directory that will be used to save result files of comparison documents

Note: Keep in mind, LIC_PATH, FILES_DIR and RESULT_DIR paths are point to the folders inside Docker container

Keeping data between runs

There is a common need to keep files between application runs. To do it you need to use Docker’s volumes. For example, you can add parameter -v groupdocs_comparison_dropwizard_volume:/home/groupdocs/app/MyDocumentSamples together with passing environment variable FILES_DIR to create new volume and pass it as directory with files. In this way command be like:

A little details about the command:

  • Option --env FILES_DIR=/home/groupdocs/app/MyDocumentSamples configures Comparison application to use directory /home/groupdocs/app/MyDocumentSamples inside Docker container as folder to keep files. You can change the path to any other, physically this directory does not exists in Docker image
  • Option -v groupdocs_comparison_dropwizard_volume:/home/groupdocs/app/MyDocumentSamples says Docker to create new volume with name groupdocs_comparison_dropwizard_volume and to map it into container as a directory /home/groupdocs/app/MyDocumentSamples. In this way, any access inside the container to MyDocumentSamples will actually make changes inside the volume. So that stopping container that was run with option --rm or manual deleting the container will not have any effect on volume and files inside it. You can easily run new container with attaching the volume to it and files will be available again. Note: groupdocs_comparison_dropwizard_volume is just name of the volume that can be used, for example, for deleting the volume. You can change it on your taste:)

Advantages of using Comparison sample with Docker

GroupDocs.Comparison API is a modern library that has lots of supported file formats and can be used to compare files, preview changes, accept or reject them, extract source/target and result texts, generate preview of file, generate summary page and much more. Tn the same time, Docker is a modern technology that gives you an opportunity to build and/or run applications without having installed environment required to it. Connected to Dropwizard Comparison application, you don’t need to have Java, Maven and other things installed and configured.

Get a Free API License

You can get a free temporary license in order to use the API without the evaluation limitations.

Conclusion

Reading this article, we learned how to run GroupDocs.Comparison for Java Dropwizard sample that can be used as a core of incredible application for comparing photos, Word, Excel, PowerPoint and other documents. There are highlighted changes on the result document. Now you can build your own comparer app or use these features within your Java applications by using GroupDocs.Comparison API.

For more details, options, and examples, you can go through the documentation and GitHub repository. Reach us on the forum for your queries.

See also