Java 11 on AWS beanstalk for Spring boot project

Since you're using Java 11 why not take advantage of Java and Elastic Bean Stalks docker support and create a docker image with JDK11 and use this to deploy?

If you choose not to go down this path and you want to want to target a lower version of java to use elastic beanstalk with Java 8 you can try something like this.

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>11</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version. The pitfall is unintended usage of APIs that only exist in later JREs which would make your code fail at runtime with a linkage error. To avoid this issue, you can either configure the compiler's boot classpath to match the target JRE or use the Animal Sniffer Maven Plugin to verify your code doesn't use unintended APIs. In the same way, setting the source option does not guarantee that your code actually compiles on a JDK with the specified version. To compile your code with a specific JDK version, different than the one used to launch

Keep in mind though that if you compile and run your code on Java 8, you cannot use classes that have been added to Java's standard library in Java 11, because those will not be present on Java 8. link

While searching, I found that support for OpenJDK11 may be coming. we re-affirm that the OpenJDK 8 and OpenJDK 11 Java runtimes in Amazon Linux 2 will continue to receive free long-term support from Amazon until at least June 30, 2023 Link


You can install java 11 on your instances using ebextensions. Just create a folder .ebextensions in your source bundle and add there one file with following name 10_java.config and content:

[UPDATE: fixed formatting of the yaml file]

container_commands:
    100-remove-old-java:
        command: "sudo yum remove -y java-1.8.0-openjdk-headless"
    200-download-rpm-package:
        command: "wget https://d3pxv6yz143wms.cloudfront.net/11.0.4.11.1/java-11-amazon-corretto-devel-11.0.4.11-1.x86_64.rpm "
    300-install-java:
        command: "sudo yum localinstall -y java-11-amazon-corretto-devel-11.0.4.11-1.x86_64.rpm"

This will remove default java 8 and install AWS' distribution of java 11.


As of May 2020, Corretto 11 running on 64bit Amazon Linux 2 is now a managed platform in Elastic Beanstalk. Here is a reference to the Java SE platforms available:

https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.javase