Recently I was working on a proof-of-concept web application that I wanted to deploy to a public cloud for a quick demo.

I decided to use Amazon as I already had experience with it. Amazon offers several different ways to deploy a Java web application.

Amazon EC2

EC2 gives us the flexibility to install and configure whatever we want to on the box. This is a very flexible solution for someone who wants to take controll over how their application is deployed and running, but it’s drawback is that we have to do most of the server installation & configuration and the application deploy tasks by ourselves.

AWS Elastic Beanstalk

The Elastic Beanstalk is an easy-to-use service that automatically handles deployment, auto-scaling, load-balancing and health monitoring. Using Elastic Beanstalk anyone can deploy a web application to the Amazon cloud with just a few clicks.

I decided to go with the quick and easy Elastic Beanstalk option…

Elastic Beanstalk has various ways to deploy Java applications:

  1. Using Docker
  2. Deploying a war file to a Tomcat server
  3. Deploying fatjar executed from the command line

In this post I’m going to cover the option using a fatjar, which is basically a single jar file that has all classes and jar dependencies bundled in it.

To make this working in Amazon, the jar file has to be placed inside a zip file.

Create JAR and ZIP files

In this post I’m using Maven to create both the jar and the zip files discussed above. Let’s walk through a sample pom.xml file to see how it’s done:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
    <relativePath />
    <!-- lookup parent from repository -->
      <!-- NOTE: We don't need a groupId specification because the group is org.apache.maven.plugins ...which is assumed by default. -->
            <!-- this is used for inheritance merges -->
            <!-- bind to the packaging phase -->

This file is based on a pom.xml file generated for Spring Boot web applications at, and it includes a few additional changes:

  1. Make sure the packaging tag is set to jar
  2. The spring-boot-maven-plugin will take care of creating the jar file including all jar dependency inside the file itself
  3. Configure the maven-assembly-plugin to generate a zip file from the jar file using the src/assembly/zip.xml descriptor file

After configuring the maven-assembly-plugin in the pom.xml file, we’ll also need to configure the zip.xml descriptor that tells the assembly plugin how to construct the zip file itself.

<assembly xmlns=""

As you can see above, we configured the output to be zip, which is one of the many supported formats.

We also configured to include the jar file in the top level directory of the zip file. And that’s all needed by Amazon to run the application from the command line,

Sample microservice using Spring Boot

To be able to test the maven configuration, I created a simple Spring Boot web application (see below).

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

public class Application {    
  @RequestMapping(value = "/hello")   
  public @ResponseBody String helloWorld() {   
    return "Hello, World!";   
  public static void main(String[] args) {, args);    

This Application class serves the main class of the web application and will be the entry point when running the fatjar from the command line

Deploy to Elastic Beanstalk

If you haven’t signed up for AWS Elastic Beanstalk yet, you can follow this link:



Select Amazon Elastic Beanstalk Platform

Once inside the console, click on create new environment for application. Then click on Create web server select Java in the platform dropdown and click Launch Now.

Elastic Beanstalk Environment Variables

Set Environment Variable

AWS configures an nginx proxy server to forward requests to our application running on port 8080. In order to tell nginx about the port 8080, in Configuration -> Software Configuration add an Environment Variable with key and value set to PORT=8080.
And that’s it. If everything went well, you should be able to access the sample web application  on AWS!


  • zcsongor

    Great article, thanks! Tried w/o zipping, works as well.

  • Viktor Csomor

    To avoid the port configuration simply add the following to the application.yml or the file .

    port: ${PORT}

    • David Kiss

      Nice! Thanks for sharing this trick

  • Anirudh Mathad

    I just built your project out of github and tried to deploy it. I don’t seem to get the response back.

    • Anirudh Mathad

      Hadn’t enabled inbound traffic ports for HTTP. Got it! Works like a charm.