Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.jline:jline3:4.0.0-SNAPSHOT'
}
dependencies {
implementation("com.github.jline:jline3:4.0.0-SNAPSHOT")
}
<dependency>
<groupId>com.github.jline</groupId>
<artifactId>jline3</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
libraryDependencies += "com.github.jline" % "jline3" % "4.0.0-SNAPSHOT"
:dependencies [[com.github.jline/jline3 "4.0.0-SNAPSHOT"]]
JLine is a Java library for handling console input. It's similar to GNU Readline but with a focus on portability, flexibility, and integration with Java applications. See https://jline.org for its documentation.
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
<version>3.30.0</version>
</dependency>
implementation 'org.jline:jline:3.30.0'
Here's a simple example to get you started:
import org.jline.reader.*;
import org.jline.reader.impl.*;
import org.jline.terminal.*;
import org.jline.terminal.impl.*;
public class HelloJLine {
public static void main(String[] args) {
try {
// Create a terminal
Terminal terminal = TerminalBuilder.builder()
.system(true)
.build();
// Create line reader
LineReader reader = LineReaderBuilder.builder()
.terminal(terminal)
.build();
// Prompt and read input
String line = reader.readLine("JLine > ");
// Print the result
System.out.println("You entered: " + line);
} catch (Exception e) {
e.printStackTrace();
}
}
}
JLine is organized into several modules:
JLine provides full support for JPMS starting with version 4.0. The following modules are proper JPMS modules with module-info.java
:
| Module | Artifact ID | Module Name | Description |
|--------|-------------|-------------|-------------|
| Core Modules | | | |
| Native | jline-native
| org.jline.nativ
| Native library loading |
| Terminal | jline-terminal
| org.jline.terminal
| Core terminal functionality |
| Terminal FFM | jline-terminal-ffm
| org.jline.terminal.ffm
| FFM-based terminal (JDK 22+) |
| Terminal JNA | jline-terminal-jna
| org.jline.terminal.jna
| JNA-based terminal |
| Terminal JNI | jline-terminal-jni
| org.jline.terminal.jni
| JNI-based terminal |
| Reader | jline-reader
| org.jline.reader
| Line editing and reading |
| Style | jline-style
| org.jline.style
| Styling and coloring |
| Extended Modules | | | |
| Builtins | jline-builtins
| org.jline.builtins
| Built-in commands |
| Console UI | jline-console-ui
| org.jline.console.ui
| Interactive UI components (deprecated) |
| Prompt | jline-prompt
| org.jline.prompt
| Modern prompt API for interactive applications |
| Console | jline-console
| org.jline.console
| Console framework |
| Jansi Core | jline-jansi-core
| org.jline.jansi.core
| ANSI support |
| Curses | jline-curses
| org.jline.curses
| Curses-like UI components |
These modules remain as automatic modules for compatibility:
| Module | Artifact ID | Reason |
|--------|-------------|---------|
| Terminal Jansi | jline-terminal-jansi
| Legacy compatibility |
| Groovy | jline-groovy
| Groovy integration |
| Remote SSH | jline-remote-ssh
| SSH server support |
| Remote Telnet | jline-remote-telnet
| Telnet server support |
| Demo | jline-demo
| Example applications |
| Graal | jline-graal
| GraalVM native image support |
When using JLine in a modular application, add the required modules to your module-info.java
:
module your.application {
requires org.jline.terminal;
requires org.jline.reader;
requires org.jline.style; // Optional: for styling
requires org.jline.builtins; // Optional: for built-in commands
requires org.jline.console; // Optional: for console framework
requires org.jline.prompt; // Optional: for modern prompt API
requires org.jline.console.ui; // Optional: for legacy UI components (deprecated)
}
Note: The FFM terminal provider (jline-terminal-ffm
) requires JDK 22+ and native access permissions:
java --enable-native-access=org.jline.terminal.ffm your.application
JLine is licensed under the BSD License.
Contributions are welcome! Please feel free to submit a Pull Request.