You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS CodeBuild是否支持OpenJDK14?求配置实现支持的方法

AWS CodeBuild 支持 OpenJDK 14 的实现方法

Hey there! Great question—AWS CodeBuild doesn’t come with OpenJDK 14 pre-installed in its official standard images, but you absolutely can add support for it using one of two straightforward approaches:

方法一:使用自定义 Docker 镜像

If you want a reusable environment with OpenJDK 14 pre-configured, building a custom Docker image is the way to go. Here’s how:

  1. Create a Dockerfile that installs OpenJDK 14 (we’ll use Amazon Corretto 14, AWS’s distribution of OpenJDK, for reliability):
# 基于 Amazon Linux 2 基础镜像
FROM amazonlinux:2

# 安装 Amazon Corretto 14
RUN yum install -y https://corretto.aws/downloads/latest/amazon-corretto-14-x64-linux-jdk.rpm

# 设置默认 Java 和 Javac 版本为 14
RUN alternatives --set java /usr/lib/jvm/java-14-amazon-corretto.x86_64/bin/java
RUN alternatives --set javac /usr/lib/jvm/java-14-amazon-corretto.x86_64/bin/javac
  1. Build this image and push it to Amazon ECR (or another container registry of your choice).
  2. In your AWS CodeBuild project configuration, select "Custom image" as the environment and point it to your ECR image URI.

方法二:在 Buildspec.yml 中动态安装 OpenJDK 14

If you prefer not to manage a custom image, you can install OpenJDK 14 directly during the build’s install phase. The commands vary slightly based on your base image:

对于 Amazon Linux 2 环境

Update your buildspec.yml like this:

version: 0.2
phases:
  install:
    commands:
      # 安装 Amazon Corretto 14
      - yum install -y https://corretto.aws/downloads/latest/amazon-corretto-14-x64-linux-jdk.rpm
      # 设置默认 Java 版本
      - alternatives --set java /usr/lib/jvm/java-14-amazon-corretto.x86_64/bin/java
      - alternatives --set javac /usr/lib/jvm/java-14-amazon-corretto.x86_64/bin/javac
      # 验证安装成功
      - java -version
  build:
    commands:
      # 在这里添加你的构建命令,比如 mvn clean package

对于 Ubuntu 环境

Use these commands instead:

version: 0.2
phases:
  install:
    commands:
      - apt-get update
      - apt-get install -y openjdk-14-jdk
      - update-alternatives --set java /usr/lib/jvm/java-14-openjdk-amd64/bin/java
      - update-alternatives --set javac /usr/lib/jvm/java-14-openjdk-amd64/bin/javac
      - java -version
  build:
    commands:
      # 你的构建命令

小提醒

Just a heads-up: OpenJDK 14 reached end-of-life in September 2021, so it no longer receives security updates. If your project allows, consider upgrading to a long-term support (LTS) version like OpenJDK 17 for better security and stability.

内容的提问来源于stack exchange,提问作者Eric Lou

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 16:22:45