Managing dependencies when deploying your app
All Jeamlit apps have at least two dependencies: Java and Jeamlit.
Your app may have additional dependencies in the form of Java libraries (JARs) that must be available on the classpath
to properly execute your program.
There are two main solutions to run Jeamlit: as an embedded server in an existing app, or as a standalone server.
The classpath resolution mechanism depends on the solution.
Embedded Server
Jeamlit can be launched as an embedded server in an existing project with the following code:
void startJeamlitServer() {
// the Jeamlit app class
class MyApp {
public static void main(String[] args) {
Jt.text("Hello World").use();
}
}
// prepare a Jeamlit server
var server = Server.builder(MyApp.class, 8888).build();
// start the server - this is non-blocking
server.start();
}
Read the embedded installation documentation for more on how to install Jeamlit in a Maven/Gradle project.
When launched as an embedded server, Jeamlit uses the current Java runtime classpath. This typically includes the Jeamlit JAR itself and any libraries already loaded by the JVM. Include any dependency you need as you would usually do in your build too, it will be available to the Jeamlit app.
Standalone mode
Jeamlit can be launched as a standalone app server with the following:
jeamlit run App.java
Read the standalone installation documentation for more on how to install the Jeamlit CLI.
In standalone mode, there are 2 ways to add dependencies to the Jeamlit app:
-
Command-line argument
You can explicitly provide additional JAR files or directories via command-line argument.java -jar jeamlit-0.44.0-all.jar run MyApp.java -cp "/path/to/libs/*:/path/to/classes"
-
JBang-style Dependencies
In standalone mode, you can declare dependencies directly in your Java file using JBang-style comments:///usr/bin/env jbang "$0" "$@" ; exit $? //DEPS org.apache.commons:commons-math3:3.6.1 //DEPS com.fasterxml.jackson.core:jackson-core:2.15.2 import tech.catheu.jeamlit.core.Jt; import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; public class MyDataApp { public static void main(String[] args) { // Your app code here Jt.write("Hello, Jeamlit!").use(); } }
Dependencies are automatically downloaded and added to the classpath at runtime.
For more information about JBang dependency syntax, see the JBang dependencies documentation.
Install the JBang plugin for proper code completion and highlighting in your IDE: IntelliJ, VS Code.
The two methods can be combined.
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.