Java
Add Java runtime to your VMs using Amazon Corretto JDK.
Installation
npm install @freestyle-sh/with-javaUsage
import { freestyle } from "freestyle-sandboxes";
import { VmJava } from "@freestyle-sh/with-java";
const { vm } = await freestyle.vms.create({
with: {
java: new VmJava(),
},
});
const result = await vm.java.runCode({
code: 'System.out.println("Hello World!");',
});
console.log(result.stdout); // Hello World!Options
| Option | Type | Default | Description |
|---|---|---|---|
version | string | "21" | Java version to install |
Specifying a Version
const { vm } = await freestyle.vms.create({
with: {
java: new VmJava({ version: "17" }),
},
});Methods
runCode
Execute Java code and capture the output.
const result = await vm.java.runCode({
code: `
import java.util.*;
public class Main {
public static void main(String[] args) {
System.out.println("Hello from Java!");
}
}
`,
});
console.log(result.stdout);
console.log(result.stderr);
console.log(result.statusCode);Runtime
This integration installs Amazon Corretto, a no-cost, production-ready distribution of OpenJDK.