Getting Started with JLine
JLine is a Java library that brings advanced console input handling capabilities to your applications. It provides functionality similar to BSD editline and GNU readline, while offering additional features that rival the sophisticated ZSH line editor.
For detailed API documentation, check out the JLine Javadoc.
Overview
JLine enhances your command-line applications with:
- Rich command-line editing capabilities
- Customizable tab completion
- History management with search
- Syntax highlighting
- Multi-line editing
- Unicode support
- Platform-independent implementation
- Flexible keyboard mapping
- Advanced line editing features (cut/paste, word movement, etc.)
Requirements
JLine 4.x requires Java 11 or higher as the minimum runtime version.
- JLine 3.x: Supports Java 8+, Maven 3.x+
- JLine 4.x: Requires Java 11+, Maven 4.0+
Installation
Maven Dependency
Add JLine to your project using Maven:
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
<version>4.0.0</version>
</dependency>
Gradle Dependency
Or if you're using Gradle:
implementation 'org.jline:jline:4.0.0'
Java 11-21 Compatibility (JDK11 Classifier)
If you're using Java 11-21 and encounter class file version errors (e.g., UnsupportedClassVersionError or build errors about Java 22 bytecode), use the jdk11 classifier. This variant excludes the FFM terminal provider which requires Java 22+.
Note: JLine 4.x requires Java 11+ as the minimum runtime version. For Java 8 support, use JLine 3.x with the jdk8 classifier.
Maven:
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
<version>4.0.0</version>
<classifier>jdk11</classifier>
</dependency>
Gradle:
implementation 'org.jline:jline:4.0.0:jdk11'
The jdk11 classifier artifact:
- Contains all JLine functionality
- Excludes the FFM terminal provider (
org.jline.terminal.impl.ffm.*classes compiled with Java 22) - Uses JNI or Exec providers for native terminal access instead
- Compatible with Java 11-21
- See Terminal Providers for more information
Basic Usage
Here's a simple example to get you started with JLine:
Loading snippet: JLineExample...
This simple example demonstrates how to:
- Create a terminal instance
- Build a line reader
- Read input from the user with a custom prompt
Next Steps
Now that you have a basic understanding of JLine, here's a recommended learning path:
-
Terminal Handling: Learn how to create and configure terminals for different environments
-
Line Reading: Explore the LineReader capabilities for advanced input handling
-
Tab Completion: Add tab completion to provide suggestions as users type
-
Command History: Implement history to allow users to recall previous commands
-
Advanced Features: Dive into advanced topics like:
-
Shell: Build interactive command-line applications with the Shell module
- Commands, pipelines, aliases, job control, syntax highlighting
-
Modules: Explore JLine's specialized modules:
-
Troubleshooting: Refer to the troubleshooting guide if you encounter issues
JLine offers a rich set of features to create sophisticated command-line interfaces. The examples in this documentation will help you leverage these capabilities in your applications.