JAR Tool
Elide ships a native-compiled jar tool — the same implementation as the JDK's jar, but compiled ahead-of-time with GraalVM. This eliminates JVM startup overhead entirely, making JAR assembly near-instant even for scripting and CI pipelines where the JVM cold-start cost would otherwise dominate. It is exposed in two ways:
- Drop-in replacement —
elide jar -- [OPTION...]passes arguments directly to the embeddedjartool with no JVM startup cost. - Build system integration —
elide buildassembles JARs automatically based on artifact declarations inelide.pkl.
A third shortcut — elide javac --jar — compiles Java source and packages the result into a JAR in one step.
---
Drop-in Usage
elide jar exposes the embedded sun.tools.jar.JarToolProvider implementation — natively compiled, so it starts instantly without a JVM. All arguments after -- are forwarded to the underlying tool verbatim, giving you full compatibility with existing jar invocations at a fraction of the startup time.
elide jar -- [OPTION...] [ [--release VERSION] [-C dir] files] ...There are no Elide-specific options before -- at this time. The -- separator is still required.
File and directory arguments must be specified as paths, not bare filenames. Use ./Foo.class, ./classes.jar, or absolute paths like /path/to/file. Bare names without a path prefix (e.g. Foo.class) will produce an error.
Main Operations
| Flag | Short | Description |
|---|---|---|
—create | -c | Create an archive |
—extract | -x | Extract files from an archive |
—list | -t | List the table of contents |
—update | -u | Update an existing archive |
—describe-module | -d | Print the module descriptor or automatic module name |
—validate | Validate a multi-release JAR for API consistency across versions |
Common Modifiers
| Flag | Description |
|---|---|
-f FILE, —file=FILE | Archive file name (omit to use stdin/stdout) |
-C DIR . | Change to the given directory and include all files from it |
-m FILE, —manifest=FILE | Include manifest from the given file |
-M, —no-manifest | Do not create a manifest |
-e CLASS, —main-class=CLASS | Application entry point for executable JARs |
—release VERSION | Place following files under META-INF/versions/VERSION/ |
—module-version=VERSION | Set the module version |
—module-path | Location of module dependencies for hash computation |
—hash-modules=PATTERN | Compute and record hashes of matched modules |
-0, —no-compress | Store only; no ZIP compression |
—date=TIMESTAMP | ISO-8601 timestamp for entry metadata |
-k, —keep-old-files | Do not overwrite existing files during extraction |
—dir | Directory to extract into |
-v, —verbose | Verbose output |
Examples
Create an archive from two class files:
elide jar -- --create --file ./classes.jar ./Foo.class ./Bar.classCreate an archive from a directory with a custom manifest:
elide jar -- --create --file ./classes.jar --manifest ./mymanifest -C ./foo/ .Create an executable modular JAR:
elide jar -- --create --file ./app.jar --main-class com.example.Main --module-version 1.0 \
-C ./build/classes .Update a non-modular JAR to a modular JAR:
elide jar -- --update --file ./app.jar --main-class com.example.Main --module-version 1.0 \
-C ./build/classes module-info.classCreate a multi-release JAR:
elide jar -- --create --file ./mr.jar -C ./foo classes --release 9 -C ./foo9 classesList the contents of a JAR:
elide jar -- --list --file ./app.jarExtract a JAR into a directory:
elide jar -- --extract --file ./app.jar --dir ./extracted---
Build System Integration
When using elide build with an elide.pkl project file, JAR packaging is handled automatically by the build task graph. Three artifact types are supported: classes JARs, sources JARs, and Javadoc JARs.
Declaring Artifacts
Artifacts are declared under the artifacts mapping in elide.pkl. Import elide:Jvm.pkl to access the JAR types:
amends "elide:project.pkl"
import "elide:Jvm.pkl" as Jvm
import "elide:Sources.pkl" as Src
name = "my-library"
sources {
["main"] = new Src.SourceSetSpec {
paths {
"src/main/java<<>>*.java"
}
}
}
artifacts {
["app"] = new Jvm.Jar {
name = "my-library"
sources { "main" }
}
["sources"] = new Jvm.SourceJar {
from { "main" }
}
["docs"] = new Jvm.JavadocJar {
from { "main" }
}
}Classes JAR (Jvm.Jar)
Packages compiled .class files from upstream compilation tasks, along with any declared resources, into a single JAR. The manifest is generated automatically and includes Manifest-Version, Created-By, Implementation-Title, Implementation-Version, and Main-Class (if an entrypoint is configured).
artifacts/jar/{name}/{name}.jar
Options:
| Field | Type | Default | Description |
|---|---|---|---|
name | String? | artifact key | Filename for the output JAR (without .jar) |
sources | Listing<String> | { "main" } | Source sets whose compiled classes to include |
resources | Mapping<path, path> | empty | Resource files to embed in the JAR |
manifest | Mapping<String, String> | empty | Additional manifest key-value entries |
manifestFile | String? | none | Path to a manifest file to use |
excludes | Listing<String> | empty | Glob patterns for files to exclude |
options.compress | Boolean | true | Whether to apply ZIP compression |
options.defaultManifestProperties | Boolean | true | Whether to add standard manifest entries |
options.entrypoint | String? | none | Main class for an executable JAR |
artifacts {
["app"] = new Jvm.Jar {
name = "my-app"
sources { "main" }
options {
entrypoint = "com.example.Main"
}
}
}artifacts {
["app"] = new Jvm.Jar {
name = "my-library"
sources { "main" }
manifest {
["Implementation-Vendor"] = "Acme Corp"
["Bundle-SymbolicName"] = "com.example.my-library"
}
}
}artifacts {
["app"] = new Jvm.Jar {
name = "my-app"
sources { "main" }
resources {
["/config/defaults.properties"] = "src/main/resources/defaults.properties"
}
}
}Sources JAR (Jvm.SourceJar)
Packages source files from the declared source sets into a JAR with a -sources classifier. Commonly used for IDE support and Maven publishing.
artifacts/jar/{name}/{name}-sources.jar
| Field | Type | Default | Description |
|---|---|---|---|
from | Listing<String> | empty | Source sets to package |
classifier | String? | "sources" | Custom classifier for the output filename |
excludes | Listing<String> | empty | Glob patterns to exclude |
includes | Listing<String> | empty | Glob patterns to include |
artifacts {
["sources"] = new Jvm.SourceJar {
from { "main" }
excludes { "**/*.generated.java" }
}
}Javadoc JAR (Jvm.JavadocJar)
Runs the javadoc tool over Java source files and packages the resulting HTML documentation into a JAR with a -javadoc classifier.
artifacts/jar/{name}/{name}-javadoc.jar
| Field | Type | Default | Description |
|---|---|---|---|
from | Listing<String> | empty | Source sets containing Java files to document |
links | Listing<String> | empty | External documentation URLs to link |
excludes | Listing<String> | empty | Package patterns to exclude |
windowTitle | String? | "{name} API" | Browser window title |
docTitle | String? | "{name} API Documentation" | Documentation page title |
groups | Mapping<String, Listing<String>> | empty | Package groupings (title -> packages) |
artifacts {
["docs"] = new Jvm.JavadocJar {
from { "main" }
windowTitle = "My Library API"
links {
"https:<<>>
}
excludes { " com.example.internal" }
}
}---
Compile and Package in One Step
elide javac accepts a --jar flag that compiles Java sources and immediately packages the compiled classes into a JAR, without needing a separate elide jar invocation.
elide javac --jar < output.jar> [--manifest < manifest-file>] -- <source files...>The compilation output goes to target/ in the current working directory. The JAR is then assembled from that directory.
elide javac --jar ./target/app.jar -- ./src/Main.java ./src/Util.java elide javac --jar ./target/app.jar --manifest ./src/MANIFEST.MF -- ./src/Main.java--jar and --manifest are Elide flags and must appear before the -- separator. Source files go after --.