kantanj is a small, single-file C utility that helps you create, build, run and manage minimal Java (Maven) projects from the command line. It was designed as a pragmatic, portable replacement for a shell helper script: it detects Java via which java, corrects JAVA_HOME when necessary, creates a basic Maven pom.xml and a starter App.java, and wraps mvn for building and running.
curl -fsSL https://raw.githubusercontent.com/nthnn/kantanj/refs/heads/main/install.sh | bash- Create a minimal Maven project (pom +
src/main/java/.../App.java) from a package name. - Build the project with Maven (executes
mvn -DskipTests package). - Run the project's JAR (builds automatically if needed).
- Clean the project's
targetdirectory. - Best-effort install helper to install JDK 21 and Maven via
apt(Debian/Ubuntu). - Detects Java via
which javaand computes the correctJAVA_HOME(fixes cases whenJAVA_HOMEwas incorrectly set to thejavabinary). - Small, portable C code (single translation unit).
- Linux (tested on Debian/Ubuntu-like systems). Many utilities rely on standard Unix tools.
gcc(to buildkantanj.c) or any compatible C compiler.mvn(Apache Maven) —kantanjcan attempt to install Maven viaaptwhen usinginstallcommand.java— a JDK (OpenJDK/Temurin) is required to build and run projects.kantanjattempts to detect and fixJAVA_HOMEwhere possible.
Note: The built-in
installcommand attemptsaptinstalls and Adoptium repo steps; it is not guaranteed to work for all distros. If your distro is not Debian/Ubuntu-based, install Java and Maven using your platform package manager.
- Build the program:
gcc -O2 -std=c11 -Wall -Wextra -o kantanj kantanj.c- (Optional) Install to
/usr/local/bin:
sudo install -m 0755 kantanj /usr/local/bin/kantanj- Create a project:
kantanj create helloworld com.example.hello- Build:
kantanj build helloworld- Run:
kantanj run helloworld arg1 arg2- Clean:
kantanj clean helloworldUsage: kantanj <command> [args]
Commands:
install Install JDK 21 and Maven (attempt via apt)
create <name> <package> Create a basic maven project (e.g. com.example)
build <name> Build project using mvn (uses ~/.m2/settings.xml)
run <name> [args...] Run project's jar (builds if needed)
clean <name> Remove project's target directory
Create a project helloworld with package com.example.hello:
kantanj create helloworld com.example.helloThis creates:
helloworld/
pom.xml
src/main/java/com/example/hello/App.java
The pom.xml will use groupId = com.example.hello and artifactId = helloworld. The main class will be com.example.hello.App.
Build:
kantanj build helloworldRun (passes args to Java program):
kantanj run helloworld foo barClean:
kantanj clean helloworldInstall prerequisites (try to install JDK 21 + Maven via apt; may prompt for sudo):
sudo kantanj installor, from non-root:
kantanj installkantanj will try to use sudo when needed.
Many Java tools (including Maven) expect JAVA_HOME to refer to the JDK home directory (for example /usr/lib/jvm/temurin-21-jdk-amd64), not to the java binary itself.
kantanj:
- Detects Java using
which java(so it follows the user's PATH). - Resolves symlinks with
realpath. - Converts the path of the
javabinary to a reasonableJAVA_HOME(if.../bin/javais detected, it uses the parent directory asJAVA_HOME). - Sets
JAVA_HOMEfor the process that runs Maven (somvnsees a validJAVA_HOMEeven if the environment was set wrongly).
This approach fixes the common situation where JAVA_HOME is accidentally set to /usr/lib/jvm/temurin-21-jdk-amd64/bin/java (binary) instead of /usr/lib/jvm/temurin-21-jdk-amd64 (home).
Build locally:
gcc -O2 -std=c11 -Wall -Wextra -o kantanj kantanj.cTurn on more warnings (optional):
gcc -O2 -std=c11 -Wall -Wextra -Wpedantic -o kantanj kantanj.cRun the program locally without installing:
./kantanj create myproject com.example.myproj
./kantanj build myproject
././kantanj run myprojectIf changes are made and you want to install the binary:
sudo install -m 0755 kantanj /usr/local/bin/kantanjkantanj.cis a single C file intentionally kept self-contained for simplicity.- The program uses
system()for a few operations (e.g. callingmvn,apt-get, orrm -rf). This keeps the code straightforward, but be mindful of shell injection if you integrate the tool into other automated flows — do not pass untrusted data intokantanjcommands that would be composed into shell commands. - File writing and directory creation are implemented in C (no shell required).
createwrites a minimalpom.xmlwithmaven-shade-pluginconfigured sopackageproduces an executable fat JAR.installattemptsaptinstalls and a best-effort attempt to add the Adoptium apt repo. It does not implement tarball extraction and fullupdate-alternativesregistration. Ifinstallfails, install JDK/Maven manually for your platform.
The JAVA_HOME environment variable is not defined correctly (Maven error)
-
This means
JAVA_HOMEpoints to a path Maven does not accept (commonly thejavabinary).kantanjattempts to detect and correctJAVA_HOMEautomatically. To verify:which java realpath $(which java) echo $JAVA_HOME
-
If
echo $JAVA_HOMEprints something ending with/bin/java, correct it:export JAVA_HOME=/usr/lib/jvm/temurin-21-jdk-amd64Then re-run
kantanj build ....
Maven download failures (network / 502s)
kantanjwrites a minimal~/.m2/settings.xmlthat mirrors central torepo1.maven.org. If your environment uses a corporate proxy or internal mirror, adjust~/.m2/settings.xmlaccordingly.
apt install fails on non-Debian systems
- The
installcommand targets Debian/Ubuntu. For other distros, use the distro's package manager (dnf, yum, pacman, zypper) or install a JDK manually.
Copyright 2025 - Nathanne Isip
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
v0.1— initial single-file C implementation:create,build,run,cleancommands.installhelper (apt-focused).JAVA_HOMEauto-correction (computed fromwhich java).