LogoFreestyle

Java

Add Java runtime to your VMs using Amazon Corretto JDK.

Installation

npm install @freestyle-sh/with-java

Usage

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

OptionTypeDefaultDescription
versionstring"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.

On this page

Freestyle AI

Documentation assistant

Experimental: AI responses may not always be accurate—please verify important details with the official documentation.

How can I help?

Ask me about Freestyle while you browse the docs.