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

升级Ubuntu 16.04至18.04后Tomcat 8.5无法启动,报NoSuchMethodError错误

Fixing Tomcat 8.5 Startup Error After Ubuntu 16.04 → 18.04 Upgrade

That NoSuchMethodError related to ByteBuffer.limit(I)Ljava/nio/ByteBuffer; is almost always caused by a Java version mismatch between what Tomcat expects and what it's actually running on. Here's how to resolve it:

Root Cause

Tomcat 8.5 requires a minimum of Java 8, but the error indicates your Tomcat instance is either running on an older Java version (pre-8) or there's a conflict between the Java version Tomcat was compiled for and the one in use. Ubuntu 18.04 ships with OpenJDK 11 by default, but after upgrading, multiple Java versions might be installed, and Tomcat could be picking the wrong one.

Step-by-Step Solutions

1. Verify the Java Version Tomcat is Using

First, check your system's default Java version:

java -version

For Ubuntu's packaged Tomcat, check the configured JAVA_HOME:

cat /etc/default/tomcat8.5 | grep JAVA_HOME

If you installed Tomcat manually, look for a setenv.sh file in the bin directory of your Tomcat installation to see which Java version it's using.

2. Set the Correct Java Version as Default

If multiple Java versions are installed, use update-alternatives to set Java 8 or 11 (both compatible with Tomcat 8.5) as the default:

sudo update-alternatives --config java
sudo update-alternatives --config javac

Select the number corresponding to Java 8 or 11 from the provided list.

3. Explicitly Set JAVA_HOME for Manual Tomcat Installations

For manual Tomcat setups, create or edit the setenv.sh file in Tomcat's bin directory to point to the correct Java installation. For example:

sudo nano /opt/tomcat8.5/bin/setenv.sh

Add these lines (adjust the path to match your Java installation):

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

Save the file and make it executable:

sudo chmod +x /opt/tomcat8.5/bin/setenv.sh

4. Update Ubuntu's Packaged Tomcat

If you're using the official Ubuntu Tomcat package, ensure it's updated to the latest version compatible with Ubuntu 18.04:

sudo apt update && sudo apt upgrade tomcat8.5

5. Check for Conflicting Libraries in Web Apps

Occasionally, web applications include outdated or incompatible JAR files in their WEB-INF/lib directory that conflict with Tomcat's dependencies. Scan your apps' WEB-INF/lib folders for any JARs containing Java core classes (like nio-related files) and remove them—these should never be included in a web app's lib directory.

After making these changes, restart Tomcat:

sudo systemctl restart tomcat8.5

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:48:55