Windows: Unable to Run sbt with installed sbt-java MSI, keeps getting java.lang.NoClassDefFoundError

Abstract: Fix java.lang.NoClassDefFoundError in sbt on Windows by correcting JAVA_HOME and PATH environment variables or reinstalling the sbt-java MSI.

Created: 2026-09-01 by

The java.lang.NoClassDefFoundError when running sbt on Windows after installing the sbt-java MSI is typically caused by an incorrect Java Home path or a corrupted classpath environment variable. The most effective fix is to verify that the JAVA_HOME environment variable points to the correct JDK installation directory and to ensure that sbt can locate it via the PATH. Reinstalling the MSI often resets these variables correctly, but manual verification is usually required.

Understanding the Error Context

The error java.lang.NoClassDefFoundError indicates that the Java Virtual Machine (JVM) attempted to load a class definition at runtime but could not find the compiled bytecode for that class in the classpath. In the context of sbt (Simple Build Tool), this almost always happens because the underlying Java process cannot initialize properly due to missing dependencies or misconfigured environment variables. When you install the sbt-java MSI package, it is designed to configure your system to run Java-based build tools without requiring a separate manual JDK installation in many cases, or it sets up specific paths for the bundled JRE.

If the environment variables are not set correctly after installation, sbt may attempt to launch with a partial or empty classpath, leading to immediate failure before any build logic is executed. This is distinct from a missing source file error; it is a fundamental infrastructure issue where the tool cannot even start its internal JVM. Users often encounter this immediately after trying to run sbt compile or simply sbt for the first time post-installation.

Verifying Environment Variables

The primary suspect for this issue on Windows is the JAVA_HOME environment variable. The sbt launcher script relies on this variable to determine which Java executable to use. If JAVA_HOME is unset, points to a non-existent directory, or points to a JRE instead of a full JDK (depending on your sbt version requirements), the classloader will fail. To check this, open the Command Prompt and type echo %JAVA_HOME%. If this returns nothing or an incorrect path, you must update it.

To update JAVA_HOME, navigate to System Properties > Advanced > Environment Variables. Look for JAVA_HOME in the System variables section. Ensure the value points to the root directory of your JDK installation, such as C:\Program Files\Java\jdk-17. Do not include the bin subdirectory in this path. After changing it, you must restart your Command Prompt or IDE to pick up the new values. It is also critical to check the PATH variable. Ensure that %JAVA_HOME%\bin is present in the PATH so that the java command is accessible globally. If you have multiple Java versions installed, the order in the PATH matters; the desired JDK should appear earlier in the list than any other Java installations.

Reinstalling the sbt-java MSI

If the environment variables appear correct but the error persists, the MSI installation itself may have failed to register the necessary registry keys or shell associations. A clean reinstall is often more reliable than troubleshooting individual settings. Before reinstalling, it is advisable to uninstall the existing sbt-java package via the Control Panel or Settings > Apps. This ensures that old configuration remnants do not interfere with the new installation.

During reinstallation, pay close attention to the setup wizard. Some versions of the sbt-java installer offer options to automatically configure environment variables. If available, select the option to "Add sbt to PATH" or "Configure JAVA_HOME". If you are using a custom JDK installation alongside sbt, choose the option that allows you to specify the JDK location manually. After the installation completes, open a fresh Command Prompt window and run sbt --version. This command forces sbt to initialize its environment and report its status. If it outputs the version number without errors, the classpath issues have been resolved.

Checking for Conflicting Java Installations

Windows systems often accumulate multiple Java installations over time, which can lead to conflicts. For instance, having both Oracle JDK and OpenJDK installed, or having older JREs lingering in the System32 folder, can cause the wrong java.exe to be invoked. Use the command where java in the Command Prompt to see all locations where the java executable is found. The first path listed is the one that takes precedence. If the first path does not correspond to your intended JAVA_HOME, you need to adjust your PATH variable to prioritize the correct directory.

In some cases, users may need to explicitly tell sbt which Java home to use if the automatic detection fails. While the previous draft suggested editing scripts, a safer approach is to set the SBT_OPTS environment variable. You can add -Djava.home="C:\Path\To\Your\JDK" to SBT_OPTS. This overrides the default behavior without modifying the core installation files. This method is particularly useful if you are working with a project that requires a specific Java version different from the system default.

Clearing Cached State

Occasionally, sbt caches metadata about the Java environment in its local repository. If you changed your JAVA_HOME or updated your JDK, sbt might still be trying to use cached classes from the previous configuration. Clearing the cache can force sbt to re-evaluate the classpath. Delete the .ivy2 and .sbt directories in your user home folder (%USERPROFILE%\.ivy2 and %USERPROFILE%\.sbt). Be aware that this will remove locally downloaded dependencies, so you may need to wait for sbt to re-download them during the next build. This step is often the final solution when environment variables are verified to be correct.

Frequently Asked Questions

Why does sbt work in IntelliJ but fail in CMD?

This usually happens because your IDE has its own embedded JDK configuration that overrides system environment variables. IntelliJ IDEA often uses its bundled JDK or a user-specified SDK that is independent of the Windows JAVA_HOME. To fix this, ensure that the Project Structure SDK in IntelliJ matches the JDK configured in your system environment variables.

Can I use sbt without installing the JDK separately?

Yes, the sbt-java MSI includes a JRE sufficient for running sbt itself. However, if your Scala project requires a specific JDK version for compilation, you must still install that JDK and point JAVA_HOME to it. The bundled JRE is primarily for the sbt launcher, not for compiling your application code.

What if my JAVA_HOME contains spaces?

Spaces in the JAVA_HOME path can sometimes cause parsing errors in batch scripts. Enclose the path in quotes within the Environment Variables dialog. For example, use "C:\Program Files\Java\jdk-17". Most modern sbt versions handle quoted paths correctly, but ensuring proper quoting prevents legacy script issues.

How do I know if sbt is using the correct Java version?

You can check by running sbt "show javaHome" in the sbt console. This command prints the exact directory path that sbt has detected for the Java Home. Compare this output with your expected JAVA_HOME value. If they differ, your environment variables or SBT_OPTS are misconfigured.

Is it safe to delete the .sbt folder?

It is generally safe to delete the .sbt folder in your user home directory, as it contains only cached metadata and downloaded dependencies. Your actual project source code remains untouched. Deleting it forces sbt to rebuild its cache, which can resolve persistent classloading errors related to stale artifacts.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More