Note
Prefer to read code directly? Take a look at the corresponding example project on GitHub.
Jeamlit Embedded
This method embeds Jeamlit as a dependency in your existing Maven or Gradle project. This method is best for complex apps, existing systems, and production deployments.
This page will walk you through adding Jeamlit to your Maven or Gradle project, creating a simple interactive app, and launching an embedded server. You'll build the same click counter app but with full control over the server lifecycle.
Prerequisites
As with any Java project, you'll need:
-
Java JDK >= 21
Download and install a Java JDK (we recommend Eclipse Adoptium).
You can verify your Java installation by running:
java --version
-
Maven or Gradle
- Maven: Download from maven.apache.org or use the Maven wrapper (
mvnw
) included in most projects - Gradle: Download from gradle.org or use the Gradle wrapper (
gradlew
)
- Maven: Download from maven.apache.org or use the Maven wrapper (
-
An IDE (recommended)
We recommend IntelliJ IDEA for the best hot-reload experience with Jeamlit.
Setup
With Maven
-
Add the Jeamlit dependency to your
pom.xml
:<dependencies> <dependency> <groupId>io.jeamlit</groupId> <artifactId>jeamlit</artifactId> <version>0.44.0</version> </dependency> <!-- Optional: Add any other dependencies your app needs --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-math3</artifactId> <version>3.6.1</version> </dependency> <!-- Recommended: Add a logging implementation if you don't have one already --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.5.18</version> </dependency> </dependencies>
-
Make sure your
pom.xml
specifies Java 21:<properties> <maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>
With Gradle
-
Add the Jeamlit dependency to your
build.gradle
:dependencies { implementation 'io.jeamlit:jeamlit:0.44.0' // Optional: Add any other dependencies your app needs implementation 'org.apache.commons:commons-math3:3.6.1' // Recommended: Add a logging implementation implementation 'ch.qos.logback:logback-classic:1.5.18' }
-
Make sure your
build.gradle
specifies Java >= 21:java { toolchain { languageVersion = JavaLanguageVersion.of(21) } }
Create your Jeamlit app
- Create
src/main/java/App.java
with your Jeamlit application:
import io.jeamlit.core.Jt;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
public class App {
public static void main(String[] args) {
Jt.title("Hello World !").use();
Jt.markdown("## A simple click app").use();
// initialize state - values in the session state are maintained at each update
Jt.sessionState().putIfAbsent("count", 0);
// if button is clicked, increment the count value
if (Jt.button("Click me").use()) {
Jt.sessionState().computeIfPresentInt("count", (k, v) -> v + 1);
}
// display the count
int count = Jt.sessionState().getInt("count");
boolean plural = count > 1;
Jt.markdown("The button was clicked **%s** time%s".formatted(count, plural ? "s" : ""))
.use();
// Use the imported library apache commons-math
Jt.divider().use();
Jt.markdown("## Using imported apache math dependency").use();
double[] values = {1.2, 2.3, 3.4, 4.5, 5.6};
DescriptiveStatistics stats = new DescriptiveStatistics(values);
double stdDev = stats.getStandardDeviation();
Jt.text("Computed statistic with Apache commons-math: " + stdDev).use();
}
}
- Create
src/main/java/Launcher.java
to start the embedded server:
import io.jeamlit.core.Server;
public class Launcher {
public static void main(String[] args) {
final var server = Server.builder(App.class, 8080).build();
server.start();
}
}
Build and run
With Maven
-
Build your project:
./mvnw clean install
-
Run the Jeamlit server:
./mvnw compile exec:java -Dexec.mainClass="Launcher"
-
Open your browser at http://localhost:8080 to see your app!
-
To stop the server, press
Ctrl+C
in the terminal.
With Gradle
-
Build your project:
./gradlew build
-
Run the Jeamlit server:
./gradlew run --main-class=Launcher
-
Open your browser at http://localhost:8080 to see your app!
-
To stop the server, press
Ctrl+C
in the terminal.
Development with hot-reload
IntelliJ IDEA Setup
- Open your project in IntelliJ IDEA
- Run
Launcher.java
in Debug mode (not Run mode) - Open your browser at http://localhost:8080
- Edit
App.java
and add some code, for example:Jt.markdown("**OMG THE HOT-RELOAD IS REAL**").use();
- When you see the "Code Change" modal in IntelliJ, click it to hot-reload
- Refresh your browser to see the changes instantly!
What's next?
Read about our Basic concepts to understand Jeamlit's dataflow model
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.