@torba/java
v1.0.13
Published
OpenJDK runtime support for torba — auto-installs an [Eclipse Temurin](https://adoptium.net) JDK and exposes `${java_home}` and `${java_bin}` as standardized vars so loader templates can reference a portable Java binary.
Readme
@torba/java
OpenJDK runtime support for torba — auto-installs an Eclipse Temurin JDK and exposes ${java_home} and ${java_bin} as standardized vars so loader templates can reference a portable Java binary.
Install
npm install @torba/javaUsage
import { resolveJava } from '@torba/java';
import { resolveLwjgl3ify } from '@torba/lwjgl3ify';
const lw = await resolveLwjgl3ify({ version: '3.0.16' });
const jav = await resolveJava({ version: '21' });
return {
manifest: {
artifacts: [lw.artifacts, jav.artifacts],
vars: { ...lw.vars, ...jav.vars },
launch: lw.launch, // launch.command is `${java_bin}` already
},
};Version input
- Major —
'21','17'— resolves to the latest GA release for that major. - Full version —
'21.0.11+10'— exact Adoptium release name (jdk-prefix and-LTSsuffix are tolerated).
Options
resolveJava({
version: string,
vendor?: 'openjdk', // only OpenJDK (Temurin) is supported today
platforms?: JavaPlatform[], // override the default OS/arch matrix
apiBase?: string, // override the Adoptium API base URL
});How it works
- Resolves the requested
versionagainsthttps://api.adoptium.net/v3/. Major versions hit/feature_releases/<n>/ga(latest GA); full versions hit/release_name/eclipse/jdk-<v>(exact). - Queries each platform (linux/osx/windows × x86_64+aarch64) in parallel; soft-skips combinations that don't ship a binary.
- Emits one
Artifactper platform pointing at the GitHub-hosted release asset, with sha256 from the API and OS+arch rules so only the matching binary downloads at install time. - Each artifact has an
extract: dumprule pointing at${root}/runtimes/jdk-<major>/, so the JDK lands at${root}/runtimes/jdk-<major>/jdk-<full>/. - Sets
java_home(per OS — macOS gets the/Contents/Homesuffix) andjava_bin(${java_home}/bin/javaon POSIX,${java_home}/bin/java.exeon Windows).
@torba/installer extracts both .zip (Windows) and .tar.gz / .tgz (Linux/macOS) archives, preserving the executable bit on tar entries so bin/java stays runnable without a chmod step.
Standard ${java_home} and ${java_bin} vars
Every torba template returned by @torba/minecraft (and by any loader built on it) now sets launch.command = '${java_bin}', with java_bin defaulting to the literal 'java' (PATH lookup). When you spread @torba/java's vars over the loader's, the var resolves to the auto-installed JDK instead — without any change to the launch command.
Notes
- Vendor: only
openjdk(Eclipse Temurin) is supported. Adding Liberica, Zulu, GraalVM is a matter of plugging in another resolver. - macOS app bundles: macOS Temurin tarballs ship as
.appbundles withContents/MacOS/_CodeSignature/....${java_home}includes the/Contents/Homesuffix automatically. - Disk usage: each JDK is ~200 MB compressed, ~500 MB extracted. The archive is downloaded into
${root}/runtimes/as a sibling of thejdk-<major>/extract target — delete the leftover.tar.gz/.ziparchive there to reclaim space.
