TeaVM Documentation

repository·master·Indexed 25 days ago

https://github.com/konsoletyper/teavm

TeaVM is a tool that compiles Java bytecode to JavaScript, WebAssembly (Wasm-GC), or C, enabling Java applications to run in web browsers and other environments. The documentation covers building from source, using the TeaVM CLI for compilation and optimization, embedding TeaVM via org.teavm.tooling.TeaVMTool and org.teavm.vm.TeaVM, and utilizing the TeaVM class library, including TAbstractStringBuilder.

Tokens
1.8K
Snippets
3
Records
17
Agent score
85%

What's inside TeaVM

  1. Embed TeaVM in your program or build tool

    master

    If you prefer not to use Maven, you can embed TeaVM directly into your application or create custom plugins for build tools like Ant or Gradle.

    Warning: These embedding APIs are considered unstable and may change between versions.

    Key entry points:

    • org.teavm.tooling.TeaVMTool (from teavm-tooling artifact): The primary starting point for embedding.
    • org.teavm.vm.TeaVM (from teavm-core artifact): For deeper integration; review how TeaVMTool initializes this class to understand its usage.
  2. Run a built TeaVM WAR file

    master

    After building a sample, you can quickly test the resulting WAR file using the following Gradle tasks depending on your operating system:

    • Unix/macOS: ./gradlew :<example-name>:appRunWar
    • Windows: gradlew bat :<example-name>:appRunWar

    Replace <example-name> with the actual name of the example you wish to run.

  3. Build TeaVM samples

    master

    To build the samples in this repository, you have two options:

    1. Preferred Method: Publish TeaVM to your local repository following the instructions in the main README.
    2. Manual Method: Use the provided build.gradle.kts and update the TeaVM version to the most recent version available on Maven Central. You can find the current version number on the badge in the main README.

    Note: Some examples provide native binaries; check the specific build files for those examples.

  4. Build TeaVM from source

    master

    To build TeaVM from the source code, clone the repository and use the Gradle wrapper to publish to your local Maven repository.

    Note: Samples must be built separately following the instructions in samples/README.md.

    git clone https://github.com/konsoletyper/teavm.git
    ./gradlew publishToMavenLocal
  5. Run the JBox2D Benchmark as a Native Linux Application

    master

    On Linux, you can build and run the benchmark as a native executable using the following Gradle command. Note that you must install the required system dependencies (cmake and gtk-devel) via your Linux distribution's package manager before running this.

    $ gradle runNativeLinux
  6. Modify TAbstractStringBuilder content

    master

    Use the following methods to manipulate the character sequence:

    • delete(int start, int end): Removes the subsequence in the specified range.
    • deleteCharAt(int index): Removes the character at the specified index.
    • replace(int start, int end, TString str): Replaces the subsequence in the specified range with the given TString.
    • reverse(): Reverses the character sequence.
    • setCharAt(int index, char ch): Replaces the character at the specified index with the specified character.
  7. Search for substrings in TAbstractStringBuilder

    master

    Use indexOf and lastIndexOf to find the index of a TString within the builder.

    • indexOf(TString str): Returns the first index of the specified substring, or -1 if not found.
    • indexOf(TString str, int fromIndex): Returns the first index of the specified substring, starting at the specified index.
    • lastIndexOf(TString str): Returns the last index of the specified substring, or -1 if not found.
    • lastIndexOf(TString str, int fromIndex): Returns the last index of the specified substring, searching backward starting from the specified index.