Java bindings for various native APIs
126
stars
1,853
commits
Java
primary language
Sep 7, 2026
updated
A collection of cross-platform Java APIs for various native APIs. Currently supports OS X, Linux, Windows and FreeBSD on Intel architectures.
These APIs support Java 5 and later. Some of these APIs overlap with APIs available in later Java versions.
These bindings work for the UNIX terminal, the Windows console and Mintty from Cygwin and MSys on Windows.
See Terminals
See Prompter
See SystemInfo
See Process
See Files
See FileSystems
See WindowsRegistry
Currently ported to OS X, Linux, FreeBSD and Windows. Support for Solaris is a work in progress. Supported on:
Include native-platform.jar and native-platform-${os}-${arch}.jar in your classpath. From Gradle, you can do
this:
repositories {
maven {
name = "Gradle public repository"
url = uri("https://repo.gradle.org/gradle/public")
content {
includeGroup("net.rubygrapefruit")
includeGroup("org.gradle.fileevents")
}
}
}
dependencies {
compile "net.rubygrapefruit:native-platform:0.21"
}
Some sample code to use the terminal:
import net.rubygrapefruit.platform.Native;
import net.rubygrapefruit.platform.terminal.Terminals;
import net.rubygrapefruit.platform.terminal.TerminalOutput;
import static net.rubygrapefruit.platform.terminal.Terminals.Output.*;
Terminals terminals = Native.get(Terminals.class);
// check if terminal
terminals.isTerminal(Stdout);
// use terminal
TerminalOutput stdout = terminals.getTerminal(Stdout);
stdout.bold();
System.out.println("bold text");
Memory and add WindowsMemory for Windows.FileEvents API for watching the file system for changes.SystemInfo.getHostname(). Thanks to Tom DunstanTerminalInput.supportsRawMode() to determine whether terminal supports raw mode.Prompter to show an alternate UI when the terminal input does not support raw mode.Terminals to support running under Mintty from Cygwin and MSYS on Windows. Supported for Windows 2008 and later. TerminalOutput is supported, however TerminalInput is not.Files.stat() when the path points to a descendent of a file. Thanks to Gary Hale.Terminal to TerminalOutput.TerminalInput to read text from the terminal. Supports raw mode and arrow keys.Terminals to determine whether stdin is attached to a terminal.Terminals to force the use of ANSI escape sequences to write the terminal output.TerminalOutput to show and hide the cursor.TerminalOutput to set foreground text color to its default value.TerminalOutput to set bright and dim foreground text intensity.TerminalOutput to write text to the terminal. Anything written to System.out or System.err is no longer automatically flushed before cursor or text attributes are changed.Prompter utility class to display prompts on the terminal to ask the user various questions.Memory, for OS X only. Thanks to Paul MerlinNativeIntegrationLinkageException is thrown by Native.get() when a particular native library cannot be loaded due to a linkage error.Files.stat() and Files.listDir() that follow links.Files.stat() and listDir().Files.listDir().FileEvents, which allows an application to listen for changes to a file system directory.PosixFile.Files and WindowsFiles.FileSystem.isCaseSensitive() and FileSystem.isCasePreserving().You should avoid using this release, and use 0.10 or later instead.
You should avoid using this release, and use 0.7 or later instead.
This project uses Gradle to build. Just run gradlew in the root of the source repo.
You will need Java 8 or later to run the tests.
The g++ compiler is required to build the native library. You will need to install the g++ package for this.
Alternatively, you can use the Clang C++ compiler.
You need to install the libncurses5-dev package to pick up the ncurses header files. Also worth installing the ncurses-doc package too.
Where multi-arch support is available (e.g. recent Ubuntu releases), you can build the i386 and amd64 versions of the library on the same machine.
You need to install the gcc-multilib and g++-multilib packages to pick up i386 support.
You need to install the lib32ncurses5-dev package to pick up the ncurses i386 version.
You need to install Visual studio 2012 or later, plus the Windows SDK to allow you to build both x86 and x64 binaries.
The clang compiler is required to build the native library. You will need to install the XCode command-line tools for this.
For Solaris 11, you need to install the development/gcc-45 and system/header packages.
Run gradlew installDist to install the test application into test-app/build/install/native-platform-test. Or
gradle distZip to create an application distribution in test-app/build/distributions/native-platform-test-$version.zip.
You can run $INSTALL_DIR/bin/native-platform-test to run the test application.
When developing a new feature in native platform, you often want to test the features in a real-world project which uses native platform. There are various ways how to test the changes of native platform in the consuming project.
From the checkout directory of the consuming project you can run:
./gradlew --include-build ../native-platform ...
This assumes that native-platform is checked out in ../native-platform relative to the consuming project.
In IDEA, open the consuming project.
Then link the native-platform project.
Finally, add the linked native-platform project as a participant to the Gradle build and sync the consuming project.
WARNING: You need to use IDEA 2020.1 for the composite build to work. See https://youtrack.jetbrains.com/issue/IDEA-228368 and https://youtrack.jetbrains.com/issue/IDEA-206799.
0.22-snapshot-20200128143135+0000,
and push the changes to a branch.mavenLocal() on a developer machine./gradlew publishToMavenLocal -PonlyLocalVariants
mavenLocal() as a repository in the consuming project.0.22-dev.See this issue first.
In the meantime, this TC job should be used to publish a milestone. Add a tag afterward.
To publish manually:
build.gradle../gradlew clean :native-platform:test :native-platform:uploadJni -Prelease -PpublishUserName=<> -PpublishApiKey=<>../gradlew clean :native-platform:test :native-platform:uploadMain -Prelease -PpublishUserName=<> -PpublishApiKey=<>./gradlew clean :test-app:uploadMain -Prelease -PpublishUserName=<> -PpublishApiKey=<>gradle.properties and this readme.Use -Pmilestone instead of -Prelease to publish a milestone version.
FileWatch tests: file truncated, last modified changed, content changed, recreated as file/dir, file renamedFileWatch.Process.getPid() should return a longNative.get() when Native.initialize() fails.Terminal extend Appendable and FlushableTerminal that returns a PrintStream that can be used to write to the terminal, regardless of what
System.out or System.err point to.wchar_to_java() for system and file system info.readLink() implementation so that it does not need to NULL terminate the encoded contentNewStringUTF() anywherejava_to_char() to convert java string directly to utf-8 char string.char_to_java() to assume utf-8 encoding and convert directly to java string.char_to_java() to use iconv() to convert from C char string to UTF-16 then to java string.TERM=xtermc instead of TERM=xterm.(top 30 of 33)
Java
64.5%
C++
18.6%
Groovy
15.8%
C
1.1%
Java bindings for various native APIs
126
stars
1,853
commits
Java
primary language
Sep 7, 2026
updated
A collection of cross-platform Java APIs for various native APIs. Currently supports OS X, Linux, Windows and FreeBSD on Intel architectures.
These APIs support Java 5 and later. Some of these APIs overlap with APIs available in later Java versions.
These bindings work for the UNIX terminal, the Windows console and Mintty from Cygwin and MSys on Windows.
See Terminals
See Prompter
See SystemInfo
See Process
See Files
See FileSystems
See WindowsRegistry
Currently ported to OS X, Linux, FreeBSD and Windows. Support for Solaris is a work in progress. Supported on:
Include native-platform.jar and native-platform-${os}-${arch}.jar in your classpath. From Gradle, you can do
this:
repositories {
maven {
name = "Gradle public repository"
url = uri("https://repo.gradle.org/gradle/public")
content {
includeGroup("net.rubygrapefruit")
includeGroup("org.gradle.fileevents")
}
}
}
dependencies {
compile "net.rubygrapefruit:native-platform:0.21"
}
Some sample code to use the terminal:
import net.rubygrapefruit.platform.Native;
import net.rubygrapefruit.platform.terminal.Terminals;
import net.rubygrapefruit.platform.terminal.TerminalOutput;
import static net.rubygrapefruit.platform.terminal.Terminals.Output.*;
Terminals terminals = Native.get(Terminals.class);
// check if terminal
terminals.isTerminal(Stdout);
// use terminal
TerminalOutput stdout = terminals.getTerminal(Stdout);
stdout.bold();
System.out.println("bold text");
Memory and add WindowsMemory for Windows.FileEvents API for watching the file system for changes.SystemInfo.getHostname(). Thanks to Tom DunstanTerminalInput.supportsRawMode() to determine whether terminal supports raw mode.Prompter to show an alternate UI when the terminal input does not support raw mode.Terminals to support running under Mintty from Cygwin and MSYS on Windows. Supported for Windows 2008 and later. TerminalOutput is supported, however TerminalInput is not.Files.stat() when the path points to a descendent of a file. Thanks to Gary Hale.Terminal to TerminalOutput.TerminalInput to read text from the terminal. Supports raw mode and arrow keys.Terminals to determine whether stdin is attached to a terminal.Terminals to force the use of ANSI escape sequences to write the terminal output.TerminalOutput to show and hide the cursor.TerminalOutput to set foreground text color to its default value.TerminalOutput to set bright and dim foreground text intensity.TerminalOutput to write text to the terminal. Anything written to System.out or System.err is no longer automatically flushed before cursor or text attributes are changed.Prompter utility class to display prompts on the terminal to ask the user various questions.Memory, for OS X only. Thanks to Paul MerlinNativeIntegrationLinkageException is thrown by Native.get() when a particular native library cannot be loaded due to a linkage error.Files.stat() and Files.listDir() that follow links.Files.stat() and listDir().Files.listDir().FileEvents, which allows an application to listen for changes to a file system directory.PosixFile.Files and WindowsFiles.FileSystem.isCaseSensitive() and FileSystem.isCasePreserving().You should avoid using this release, and use 0.10 or later instead.
You should avoid using this release, and use 0.7 or later instead.
This project uses Gradle to build. Just run gradlew in the root of the source repo.
You will need Java 8 or later to run the tests.
The g++ compiler is required to build the native library. You will need to install the g++ package for this.
Alternatively, you can use the Clang C++ compiler.
You need to install the libncurses5-dev package to pick up the ncurses header files. Also worth installing the ncurses-doc package too.
Where multi-arch support is available (e.g. recent Ubuntu releases), you can build the i386 and amd64 versions of the library on the same machine.
You need to install the gcc-multilib and g++-multilib packages to pick up i386 support.
You need to install the lib32ncurses5-dev package to pick up the ncurses i386 version.
You need to install Visual studio 2012 or later, plus the Windows SDK to allow you to build both x86 and x64 binaries.
The clang compiler is required to build the native library. You will need to install the XCode command-line tools for this.
For Solaris 11, you need to install the development/gcc-45 and system/header packages.
Run gradlew installDist to install the test application into test-app/build/install/native-platform-test. Or
gradle distZip to create an application distribution in test-app/build/distributions/native-platform-test-$version.zip.
You can run $INSTALL_DIR/bin/native-platform-test to run the test application.
When developing a new feature in native platform, you often want to test the features in a real-world project which uses native platform. There are various ways how to test the changes of native platform in the consuming project.
From the checkout directory of the consuming project you can run:
./gradlew --include-build ../native-platform ...
This assumes that native-platform is checked out in ../native-platform relative to the consuming project.
In IDEA, open the consuming project.
Then link the native-platform project.
Finally, add the linked native-platform project as a participant to the Gradle build and sync the consuming project.
WARNING: You need to use IDEA 2020.1 for the composite build to work. See https://youtrack.jetbrains.com/issue/IDEA-228368 and https://youtrack.jetbrains.com/issue/IDEA-206799.
0.22-snapshot-20200128143135+0000,
and push the changes to a branch.mavenLocal() on a developer machine./gradlew publishToMavenLocal -PonlyLocalVariants
mavenLocal() as a repository in the consuming project.0.22-dev.See this issue first.
In the meantime, this TC job should be used to publish a milestone. Add a tag afterward.
To publish manually:
build.gradle../gradlew clean :native-platform:test :native-platform:uploadJni -Prelease -PpublishUserName=<> -PpublishApiKey=<>../gradlew clean :native-platform:test :native-platform:uploadMain -Prelease -PpublishUserName=<> -PpublishApiKey=<>./gradlew clean :test-app:uploadMain -Prelease -PpublishUserName=<> -PpublishApiKey=<>gradle.properties and this readme.Use -Pmilestone instead of -Prelease to publish a milestone version.
FileWatch tests: file truncated, last modified changed, content changed, recreated as file/dir, file renamedFileWatch.Process.getPid() should return a longNative.get() when Native.initialize() fails.Terminal extend Appendable and FlushableTerminal that returns a PrintStream that can be used to write to the terminal, regardless of what
System.out or System.err point to.wchar_to_java() for system and file system info.readLink() implementation so that it does not need to NULL terminate the encoded contentNewStringUTF() anywherejava_to_char() to convert java string directly to utf-8 char string.char_to_java() to assume utf-8 encoding and convert directly to java string.char_to_java() to use iconv() to convert from C char string to UTF-16 then to java string.TERM=xtermc instead of TERM=xterm.(top 30 of 33)
Java
64.5%
C++
18.6%
Groovy
15.8%
C
1.1%