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

如何在Ubuntu 16服务器上为所有用户安装兼容Tomcat的OpenJDK 9

Fixing OpenJDK 9 & Tomcat Compatibility on Ubuntu (All Users Access)

Hey there, let's resolve this issue where the openjdk-9-internal build from apt is causing Tomcat exceptions. The internal build is an early pre-release with known compatibility bugs—here's how to get a stable, properly supported OpenJDK 9 that works with Tomcat and is accessible to all server users:

Step 1: Remove the problematic internal JDK

First, fully purge the existing broken installation to avoid conflicts:

sudo apt purge openjdk-9-jdk openjdk-9-jre
sudo apt autoremove && sudo apt clean

Step 2: Install a stable OpenJDK 9 via SDKMAN

SDKMAN lets you install official, stable OpenJDK distributions (like Adoptium's builds) that are tested for compatibility. Here's how:

  1. Install SDKMAN (run this command directly):
    curl -s "https://get.sdkman.io" | bash
    
  2. Load SDKMAN into your current shell session:
    source "$HOME/.sdkman/bin/sdkman-init.sh"
    
  3. List available stable OpenJDK 9 builds:
    sdk list java
    
    Look for entries marked stable under the Java 9 section (e.g., something like 9.0.7-adpt from Adoptium).
  4. Install your chosen stable version (replace 9.0.7-adpt with the actual version from the list):
    sdk install java 9.0.7-adpt
    
  5. Set it as your current user's default JDK:
    sdk default java 9.0.7-adpt
    

Step 3: Make the JDK accessible to all users

To ensure every server user can use this stable JDK, we'll link it to a system-wide path and update alternatives:

  1. Get the full path of your installed JDK:
    echo $JAVA_HOME
    
    You'll get a path like /home/your-username/.sdkman/candidates/java/9.0.7-adpt—copy this.
  2. Create a system-wide symlink to this path:
    sudo ln -s /home/your-username/.sdkman/candidates/java/9.0.7-adpt /usr/lib/jvm/openjdk-9-stable
    
  3. Register the JDK with update-alternatives:
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/openjdk-9-stable/bin/java 100
    sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/openjdk-9-stable/bin/javac 100
    
  4. Set the new JDK as the system default:
    sudo update-alternatives --config java
    sudo update-alternatives --config javac
    
    When prompted, enter the number corresponding to /usr/lib/jvm/openjdk-9-stable to select it as default.

Step 4: Verify the setup

  • Switch to another user (e.g., su - test-user) and run these commands to confirm the correct version is available:
    java -version
    javac -version
    
    You should see output like this (version numbers may vary slightly):

    openjdk version "9.0.7"
    OpenJDK Runtime Environment AdoptOpenJDK (build 9.0.7+10)
    OpenJDK 64-Bit Server VM AdoptOpenJDK (build 9.0.7+10, mixed mode)

  • Start your Tomcat instance and verify the earlier exceptions no longer occur.

Why this works

The 9-internal build from Ubuntu's repos is an unfinished pre-release, missing critical fixes and compatibility patches required for Tomcat. By switching to a stable, officially supported OpenJDK 9 distribution, you eliminate those compatibility gaps.

内容的提问来源于stack exchange,提问作者Peter Lustig

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:15:24