Kona is a lightweight framework for building cross-platform desktop applications using Java and web technologies. It provides a simple and intuitive API for creating and managing windows, handling messages between the frontend and backend, and packaging your application for distribution.
- Cross-Platform: Write your application once and run it on multiple operating systems.
- Java + Web: Combine the power of Java for the backend with the flexibility of web technologies for the frontend.
- Simple API: A clean and modern API that makes it easy to get started.
- Automatic Environment Detection: Automatically detects whether you are in a development or production environment.
- Extensible: Easily extend the framework with custom implementations for different platforms or web view engines.
| Operating System | Architecture | Supported |
|---|---|---|
| Linux | x86_64 | ✅ |
| Windows | x86_64 | TBD |
| macOS | x86_64 | TBD |
| macOS | aarch64 | TBD |
-
Java 21+: Kona requires Java 21 or higher.
-
GTK 3 and WebKit2GTK: For Linux, you need to have GTK 3 and WebKit2GTK installed.
# Debian/Ubuntu sudo apt-get install libgtk-3-dev libwebkit2gtk-4.0-dev # Fedora/CentOS sudo dnf install gtk3-devel webkit2gtk4.0-devel
-
Create a new Java project: Start by creating a new Java project with your favorite build tool.
-
Add the Kona dependency: Add the Kona dependency to your
build.gradleorpom.xmlfile.// build.gradle repositories { mavenCentral() } dependencies { implementation 'io.github.hubertkuch:kona:0.1.0' // Replace with the latest version }
-
Create your main application class:
import io.github.hubertkuch.kona.Kona; public class Main { public static void main(String[] args) { new Kona.Builder() .title("My Kona App") .build() .run(); } }
-
Create your frontend: Create a new frontend project using your favorite web framework (e.g., React, Vue, Svelte). Install the
kona-jslibrary:npm install kona-js
-
Run your application: Run your Java application. It will automatically detect that you are in a development environment and load the content from the Vite dev server at
http://localhost:5173.
The kona-js library provides a simple way to communicate with the Java backend from your frontend.
The kona.call function sends a message to the backend and returns a promise that resolves with the response.
controller(string): The name of the controller to handle the message.action(string): The name of the action to be performed.payload(object): The data to be sent to the backend.
Example:
import kona from "kona-js";
async function handleClick() {
const response = await kona.call("test", "test", {
message: "Hello from React!"
});
console.log(response); // { response: "Hello from Java! ..." }
}You can configure your Kona application using the Kona.Builder class:
new Kona.Builder()
.title("My Custom App")
.width(1024)
.height(768)
.controllerPackage("com.example.controllers")
.initialUri("http://localhost:8080")
.build()
.run();The primary goal of Kona is to create a standalone, native binary of your application using GraalVM. This provides a lightweight, fast-starting application with no need for a separate JVM installation.
-
Install GraalVM: Follow the official instructions to install GraalVM and the
native-imagetool.sdk install java 21.0.1-graal gu install native-image
-
Build your frontend: Build your frontend project. This will typically generate a
distdirectory with your static assets. -
Copy the frontend assets: Copy the contents of the
distdirectory to thesrc/main/resources/webappdirectory in your Java project. These resources will be embedded into the native binary. -
Configure your project for GraalVM: In your project's
build.gradlefile, add the GraalVM plugin and configure it to build a native binary. Kona is a library, so it does not bundle the GraalVM plugin.plugins { id 'org.graalvm.buildtools.native' version '0.9.28' } graalvmNative { binaries { main { mainClass = 'com.example.Main' // Replace with your main class buildArgs.add('--enable-preview') } } } -
Build the native binary: Run the
nativeCompiletask to build the native binary../gradlew nativeCompile
The native executable will be created in the
build/native/nativeCompiledirectory.
Kona is licensed under the MIT License.