# JLine 4 for portable Java console interaction

> JLine 4 is a Java library for building interactive command-line experiences with line editing, history, completion, ANSI styling, password masking, and portable terminal access. It suits Java applications that need more than basic input reading.

**jline/jline3** — JLine is a Java library for handling console input.

- Repository: https://github.com/jline/jline3
- Website: https://jline.org
- Stars: 1,810 · Forks: 257
- Language: Java
- License: NOASSERTION
- Published: 2026-10-16 · Updated: 2026-10-16 · Language: en
- Canonical page: https://hysenlabs.com/projects/jline-jline3

## Why JLine 4 changes the Java console experience

JLine addresses a specific problem in Java console applications: turning raw terminal input into an interactive interface with editing, history, completion, styling, and portable terminal handling. It is aimed at developers building command-line tools, shells, remote consoles, and other applications where users need to correct a line before submitting it. The README also lists password masking, Unicode support, ANSI terminal support, and interactive ConsoleUI elements.

The library is not limited to a single terminal implementation. Its documented platform coverage includes Windows, macOS, Linux, and other Unix-like systems. That portability is the main distinction from using standard input calls directly. A Java application can build a Terminal through TerminalBuilder and pass that terminal to LineReader, rather than assuming that every environment exposes the same editing behavior.

The project has a broad surface, but that breadth creates choices. The repository is organized into modules for terminal handling, reading, prompts, styling, built-ins, console abstractions, remote SSH, and remote Telnet. Consumers should select modules rather than assume that every feature belongs in a single dependency.

## JLine terminal, reader, and module data flow

The quick-start example shows the central data flow. TerminalBuilder creates a terminal configured with system(true), LineReaderBuilder receives that terminal, and LineReader.readLine("JLine > ") handles the interaction before the application prints the returned string. The terminal is the environment-facing layer. The reader is the line-editing and input layer above it.

The architecture separates concerns through artifacts such as jline-terminal, jline-reader, jline-style, jline-prompt, and jline-builtins. The README states that JLine 4 supports JPMS and identifies proper modules including org.jline.terminal, org.jline.reader, org.jline.style, and org.jline.builtins. Some modules remain automatic modules for compatibility, including the legacy jline-terminal-jansi, remote SSH, remote Telnet, Groovy, Graal, and demo artifacts.

There is also a runtime distinction between the default artifact and the jdk11 classifier. The README says the jdk11 variant includes JLine functionality but excludes the FFM terminal provider compiled for Java 22 and later. It uses JNI or Exec providers for native terminal access instead. On Java 22 or later, the FFM provider requires the separate jline-terminal-ffm module and native access permissions. This is a packaging and runtime decision, not merely a dependency detail.

The documented terminal behavior includes ANSI escape sequences, colors, wide characters, and combining marks. These features matter for interactive rendering, but terminal support remains conditional on the provider and runtime selected by the application.

## Installing JLine 4 and creating the first prompt

JLine 4.x requires Java 11 or higher and Maven 3.9 or higher for building from source. The README gives the following Maven dependency using version 4.0.0. This version is copied from the documented example rather than inferred from the release list. Replace it with the version selected for your project when appropriate.

In Maven, add the core artifact to the dependency block for the application. The groupId is org.jline and the artifactId is jline.

```xml
<dependency>
    <groupId>org.jline</groupId>
    <artifactId>jline</artifactId>
    <version>4.0.0</version>
</dependency>
```

For a Gradle project, the README documents the equivalent dependency declaration.

```groovy
implementation 'org.jline:jline:4.0.0'
```

The first use needs a terminal, a line reader, and one read operation. Save the following as the Java application entry point, then compile and run it through the build configuration already used by your project. The prompt should appear as JLine > in an interactive terminal.

```java
import org.jline.reader.*;
import org.jline.terminal.*;

public class HelloJLine {
    public static void main(String[] args) {
        try {
            Terminal terminal = TerminalBuilder.builder()
                    .system(true)
                    .build();
            LineReader reader = LineReaderBuilder.builder()
                    .terminal(terminal)
                    .build();
            String line = reader.readLine("JLine > ");
            System.out.println("You entered: " + line);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
```

The README does not document a rollback procedure for a terminal provider or line reader.

## JPMS requires explicit module choices

JLine 4 provides JPMS support, which is useful when the application itself is modular. The README lists org.jline.terminal and org.jline.reader as proper modules, with optional modules for styling, built-ins, the console framework, the prompt API, and the deprecated console UI module.

A modular application can declare the required modules directly. The following example is the README's module declaration pattern, with the application name left as your.application.

```java
module your.application {
    requires org.jline.terminal;
    requires org.jline.reader;
    requires org.jline.style;
    requires org.jline.builtins;
    requires org.jline.console;
    requires org.jline.prompt;
}
```

Optional requires lines should be reduced when those APIs are not used. The README marks jline-console-ui as deprecated, so a new application should not select it merely because older examples or integrations use the module.

The FFM provider has a separate boundary. The README says it requires JDK 22 or later and native access permissions. The documented launch form is:

```bash
java --enable-native-access=org.jline.terminal.ffm your.application
```

Applications running on Java 11 through 21 can use the jdk11 classifier. The documented Maven form is:

```xml
<dependency>
    <groupId>org.jline</groupId>
    <artifactId>jline</artifactId>
    <version>4.0.0</version>
    <classifier>jdk11</classifier>
</dependency>
```

This classifier choice follows directly from the provider split described in the README.

## Feature fit comes with terminal-provider constraints

JLine is a good fit when users need editable input rather than a one-shot read. Emacs and Vi editing modes, customizable key bindings, persistent history, tab completion, syntax highlighting, and password masking are all documented features. The library also supports interactive elements such as menus, checkboxes, and prompts through its higher-level components.

That does not mean every application should use JLine. A batch process that only consumes standard input, or an application that does not need line editing or terminal rendering, can keep a simpler dependency set. JLine introduces terminal construction, provider selection, and runtime compatibility decisions that have no value in that narrower case.

There is another boundary around the feature modules. jline-console-ui is explicitly deprecated. jline-prompt is described as the modern prompt API, while jline-console provides a higher-level console framework. The repository therefore contains overlapping layers, and the README does not give one universal choice for every interactive application.

ANSI rendering and Unicode handling can also make behavior dependent on the actual terminal. JLine handles these concerns, but the README does not claim that every terminal environment exposes identical rendering. Applications that depend on precise colors, wide-character alignment, or combining marks should verify their target terminal and chosen provider.

## JLine and direct Java input use different levels of control

The real alternative is to use Java's direct console and input facilities without JLine. That approach is simpler for reading a single value or collecting lines in a non-interactive program. It does not provide JLine's documented layer for line editing, history search, completion, syntax highlighting, password masking, or portable terminal behavior.

The difference is architectural rather than cosmetic. JLine creates a Terminal, then constructs a LineReader around it. A direct Java implementation would read from the application's input path and format the prompt itself, leaving editing, terminal control sequences, character width handling, and provider selection to the application or runtime. The README does not provide a benchmark or claim that either approach is faster, so the choice should be based on required interaction.

A second alternative is GNU Readline, which the README names as a similar model. JLine emphasizes portability, flexibility, and integration with Java applications. JLine's documented differentiator is portability across Windows, macOS, and Unix-like systems while remaining inside the Java ecosystem. That does not eliminate the need to choose JLine modules or classify the artifact for the target JDK.

## Maintenance, releases, and license verification

The repository is not archived, and the last push was on 2026-10-14. The listed recent releases include JLine 4.4.8 on 2026-10-11, JLine 4.4.7 on 2026-10-06, and JLine 4.4.6 on 2026-09-23. These dates indicate recent repository activity, but the README does not describe a long-term support policy, a complete compatibility matrix for every module, or a release-to-release migration procedure.

There is a licensing metadata inconsistency that requires direct verification. The repository description classifies the license as Other and points to the LICENSE file, while the README badge and text identify BSD License and link to the BSD 3-Clause license. This review does not provide legal advice. Before distribution, inspect LICENSE.txt and confirm the terms that apply to the exact artifact and source version you use.

Upgrade planning should also account for the documented JLine 3.x and 4.x distinction. JLine 3.x supports Java 8 and Maven 3.x or higher, whereas JLine 4.x requires Java 11 and Maven 3.9 or higher. The README also distinguishes the jdk8 classifier for JLine 3.x from the jdk11 classifier for JLine 4.x. The upgrade path itself is not documented in the README, so dependency changes should be checked against the project files before migration.

## Conclusion

Adopt JLine 4 when a Java application needs portable, editable console interaction and can account for its module boundaries and JDK-specific terminal providers. Do not choose it for non-interactive input-only work. Verify first that jline-terminal and jline-reader fit the runtime, then inspect LICENSE.txt because repository metadata and the README describe the license differently.

## FAQ

### What Java version does JLine 4 require?

JLine 4.x requires Java 11 or higher as its minimum runtime version. Building from source requires Maven 3.9 or higher.

### When should I use the JLine jdk11 classifier?

Use the jdk11 classifier on Java 11 through 21 when you need to avoid Java 22 class files or the FFM terminal provider, which requires Java 22 or later. The README says this variant uses JNI or Exec providers for native terminal access.

### What is the difference between org.jline.reader and org.jline.console.ui?

org.jline.reader is the proper JPMS module for line editing and reading. org.jline.console.ui provides interactive UI components such as menus and checkboxes, but the README marks that module deprecated.

## Sources

- [Issues](https://github.com/jline/jline3/issues)
- [jline/jline3 on GitHub](https://github.com/jline/jline3)
- [Project website](https://jline.org)
- [README](https://github.com/jline/jline3/blob/master/README.md)
- [Releases](https://github.com/jline/jline3/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/jline-jline3
