Implementation:Apache Kafka Kafka Run Class Classpath
| Knowledge Sources | |
|---|---|
| Domains | Operations, JVM_Configuration |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
Concrete tool for constructing the JVM classpath from Kafka's modular build directories provided by kafka-run-class.sh.
Description
The classpath assembly section of kafka-run-class.sh constructs the CLASSPATH environment variable by scanning multiple module directories. It uses a should_include_file function to filter out test, source, and javadoc JARs. The default Scala version is read from gradle.properties and can be overridden via the SCALA_VERSION environment variable.
Usage
This is an internal section of kafka-run-class.sh and is not invoked directly. It runs automatically when any Kafka script delegates to the run-class launcher. Override CLASSPATH to provide a custom classpath, or set INCLUDE_TEST_JARS=true for testing.
Code Reference
Source Location
- Repository: Apache Kafka
- File: bin/kafka-run-class.sh
- Lines: L49-198
Signature
# Function to filter JAR files
should_include_file() {
# Excludes: *-test.jar, *-sources.jar, *-javadoc.jar
# Includes test JARs only if INCLUDE_TEST_JARS=true
}
# Environment variables:
# SCALA_VERSION - Scala version (default: read from gradle.properties, e.g. 2.13.18)
# INCLUDE_TEST_JARS - Include test JARs (default: false)
# CLASSPATH - Resulting classpath (output)
# Scanned directories:
# $base_dir/core/build/libs/, $base_dir/core/build/dependant-libs-${SCALA_VERSION}/
# $base_dir/clients/build/libs/, $base_dir/streams/build/libs/
# $base_dir/tools/build/libs/, $base_dir/connect/*/build/libs/
# $base_dir/libs/ (release layout)
Import
# Automatically invoked by kafka-run-class.sh
# Override: export CLASSPATH="/custom/path/*"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| SCALA_VERSION | env | No | Scala version for JAR selection (default from gradle.properties) |
| INCLUDE_TEST_JARS | env | No | Include test JARs in classpath (default: false) |
| base_dir | computed | Yes | Kafka installation root directory |
Outputs
| Name | Type | Description |
|---|---|---|
| CLASSPATH | env | Colon-separated list of all required JAR paths |
Usage Examples
Default Classpath Assembly
# Normal operation (automatic via kafka-server-start.sh)
bin/kafka-server-start.sh config/server.properties
# CLASSPATH is assembled internally
# Override Scala version
export SCALA_VERSION=2.13.18
bin/kafka-run-class.sh kafka.Kafka config/server.properties
# Include test JARs for testing
export INCLUDE_TEST_JARS=true
bin/kafka-run-class.sh kafka.tools.TopicCommand --list