Quick Start¶
This section explains how to get started quickly using the command-line mode.
Prerequisite: Jeka CLI must be installed.
Note
Using the IntelliJ Plugin is the fastest way to get started. It provides a wizard for creating various types of projects, ranging from simple scripts to full-fledged Spring Boot applications.
This quick-start guide covers muliple use cases:
- Create scripts in Java and execute from command line.
- Create a Base Application or Library.
- Create a Java Project
- Create a workable Spring-Boot Project in seconds
Notes
If you are coding in IntelliJ IDEA, after scaffolding or modifying dependencies, execute the following command to synchronize:
jeka intellij: iml
Create Scripts¶
Create a directory to host the codebase. Navigate into it and execute:
jeka base: scaffold
.
├── jeka-src <- Source root directory
│ └── Script.java
└── jeka.properties <- Configuration (Java and jeka version, default parameters...)
@JkDoc("Minimalist script for demo purpose.")
class Script extends KBean {
@JkDoc("Person to whom the greeting is intended")
public String name = "World";
@JkDoc("Print greeting on console")
public void hello() {
String greetings = "Hello " + name + " !";
System.out.println(greetings);
}
}
Run methods¶
You can run the method hello()
and changing the parameter, by executing:
jeka hello name="JeKa"
Hello JeKa !
Write Extra Methods¶
You can add extra methods relying or not on third-party dependencies as:
import com.github.lalyos.jfiglet.FigletFont;
import com.google.common.base.Strings;
import dev.jeka.core.tool.JkDep;
import dev.jeka.core.tool.KBean;
@JkDep("com.github.lalyos:jfiglet:0.0.9")
@JkDep("com.google.guava:guava:33.3.1-jre")
class Script extends KBean {
...
public void header() throws Exception {
System.out.println(Strings.repeat("-", 80));
ystem.out.println(FigletFont.convertOneLine("Hello Ascii Art !"));
System.out.println(Strings.repeat("-", 80));
}
}
jeka header
--------------------------------------------------------------------------------
_ _ _ _ _ _ _ _ _ _
| | | | ___| | | ___ / \ ___ ___(_|_) / \ _ __| |_ | |
| |_| |/ _ \ | |/ _ \ / _ \ / __|/ __| | | / _ \ | '__| __| | |
| _ | __/ | | (_) | / ___ \\__ \ (__| | | / ___ \| | | |_ |_|
|_| |_|\___|_|_|\___/ /_/ \_\___/\___|_|_| /_/ \_\_| \__| (_)
--------------------------------------------------------------------------------
- You can define multiple script methods in
Script.java
. These methods must be public, non-static, have no arguments, and return void. Script.java
can be renamed to any name and placed in any package you prefer.- There can be multiple script classes. When invoking a specific script, you can specify the class name, for example:
jeka script2: hi
. - You can also use the classes bundled with JeKa without requiring explicit declarations.
KBeans¶
Every script should inherit from the KBean
class.
KBeans can either be provided as source code (located in the jeka-src directory) or as compiled classes available in the classpath.
Jeka includes several standard KBeans, which you can list by running:
jeka --doc
Change Java Version¶
To change version of Java, edit jeka.properties:
jeka.java.version=23
Run remotely¶
Run hello
from another directory:
jeka -r /path/to/scrcipt/root-dir hello
Run hello
from remote git repo:
jeka -r https://my.githost/my-repo.git hello
Common Options/Commands:¶
jeka --help <- Displays help message
--doc <- Displays documentation on availbale scripts
--inspect <- Displays details about Jeka setup
jeka base: depTree <- Show dependency tree
Resources¶
Create a Base App or Library¶
Jeka provides a base mode, which simplifies the creation of pure Java applications or libraries by avoiding the complexity of a traditional project structure.
Despite its simplicity, this structure supports full build configuration, automated testing, native compilation, Maven publication, and Docker image creation.
To create a new code structure, run the following command:
jeka base: scaffold scaffold.kind=APP
.
├── jeka-src <- Source root directory
│ ├── _dev <- Optional package containing all non-prod (build and test)
│ │ ├── test
│ │ └── Build.java
│ └── app <- Sugested base package for production code/resources
│ └── App.java
├── jeka-output <- Generated dir where artifacts as jars, classes, reports or doc are generated
├── jeka.properties <- Build configuration (Java and jeka version, kben configurations, ...)
└── README.md <- Describes available build commands
Follow the tutorial for more details.
Create a Java Project¶
In this mode, you can create a fully-fledged project similar to Maven or Gradle.
To create a new project structure, execute:
jeka project: scaffold
.
├── src
│ ├── main <- Java code and reources
│ │ ├── java
│ │ └── resources
│ └── test <- Java code and reources for tests
│ ├── java
│ └── resources
├── jeka-src <- Optional Java (or Kotlin) code for building the project
│ └── Build.java
├── jeka-output <- Generated dir where artifacts as jars, classes, reports or doc are generated
├── dependencies.txt <- Dependency lists for compile, runtime and testing
├── jeka.properties <- Build configuration (Java and jeka version, kben configurations, ...)
├── jeka.ps <- Optional Powershell script to boot Jeka on Windows
├── jeka <- Optional bash script to boot Jeka on Linuw/MacOS
└── README.md <- Describes available build commands for building the project
Follow the tutorial for more details.
Create a Spring-Boot Project¶
To create a new project Spring-Boot, execute:
jeka -cp=dev.jeka:springboot-plugin project: scaffold springboot:
This generates the following project structure:
.
├── src
│ ├── main
│ │ ├── java
│ │ │ └── app
│ │ │ ├── Application.java. <- Spring-Boot app class
│ │ │ └── Controller.java. <- REST controller
│ │ └── resources
│ └── test
│ ├── java
│ │ └── app
│ │ └── ControllerIt.java <- Integration Test for REST controller
│ └── resources
├── jeka-src
│ └── Build.java <- Empty build class -in case of.
├── jeka-output
├── dependencies.txt <- Springboot and extra dependencies
├── jeka.properties <- Build configuration
├── jeka.ps
├── jeka
└── README.md <- Describes available build commands for building the project
Modify Layout¶
You can choose a simpler code layout structure by setting the following properties:
@project.layout.style=SIMPLE
@project.layout.mixSourcesAndResources=true
.
├── src <- Contains both Java code and resooources
├── test <- Contains both Java code and resooources for testing
Modify Dependencies¶
The dependencies are generated with the latest Spring-Boot version:
== COMPILE ==
org.springframework.boot:spring-boot-dependencies::pom:3.4.1
org.springframework.boot:spring-boot-starter-web
== RUNTIME ==
== TEST ==
org.springframework.boot:spring-boot-starter-test
Execute Commands¶
These are the most useful commands for developping Spring-Boot applications.
jeka project: pack <- Compiles, tests and creates Bootable Jar
jeka project: runJar <- Run bootable jar
jeka project: depTree <- Displays dependency tree
jeka docker: build <- Creates Docker image containing the Spring-Boot application
jeka docker: buildNative <- Creates Docker image containing the Spring-Boot application compiled to native.
Customize Docker File¶
To reduce a Docker native image size, use a distroless base image. The native executable must be statically linked as libc is unavailable in such distributions. Configure it as follows:
@native.staticLink=MUSL
@docker.nativeBaseImage=gcr.io/distroless/static-debian12:nonroot
What Next?¶
Now that you're here, you can explore the following resources to enhance your project. Learn how to include SonarQube analysis, add a ReactJS web client, perform end-to-end testing, or implement a delivery pipeline in Java: