# Elide for Java users

> Switching from a JDK with Maven or Gradle to Elide: running Java source directly with JDK 25, what changes in builds and tests, benchmarks and trade-offs.

Elide bundles JDK 25 with a build tool, Maven dependency resolver, JUnit runner and formatter in one binary.

## Run the same code

A source file with a `main` method compiles and runs directly:

```bash
elide run Main.java
```

`elide java`, `elide javac`, `elide jar` and `elide javadoc` run the JDK 25 tools without a JDK install. Their
arguments go after `--`:

```bash
elide javac -- -d out Main.java
elide java -- -cp out Main
elide jar -- --create --file app.jar -C out .
elide java -- -version
```

The distribution's `bin/` holds `java`, `javac`, `jar`, `javadoc` and `javap`, so an existing build can use it as
`JAVA_HOME`; see [JVM Toolchain](https://elide.help/docs/toolchain/jvm#existing-build-systems).

A project is an `elide.pkl` file, which also lists Maven dependencies:

```pkl
amends "elide:project.pkl"

jvm { main = "com.example.Hello" }

dependencies {
  maven {
    packages { "com.google.guava:guava:33.4.8-jre" }
  }
}
```

```bash
elide init --plain --skip-defaults --template java   # new project
elide install                                        # resolve Maven dependencies
elide build                                          # compile and assemble
elide test                                           # run JUnit tests
elide run                                            # run jvm.main
elide format -- src                                  # Google Java Format
```

JUnit is on the test classpath without a declared dependency. See [Java and Kotlin with Elide](https://elide.help/docs/jvm),
[Testing](https://elide.help/docs/toolchain/testing) and the [`elide.pkl` reference](https://elide.help/docs/elide-pkl-reference).

## What changes

| With a JDK, Maven or Gradle | With Elide |
| --- | --- |
| Install a JDK | Nothing; JDK 25 is bundled. |
| `javac -d out Main.java` | `elide javac -- -d out Main.java` |
| `java Main.java` | `elide run Main.java` |
| `pom.xml`, `build.gradle` | `elide.pkl` |
| Resolve dependencies | `elide install`; `elide install -p .` reads a `pom.xml`. |
| `mvn package`, `gradle build` | `elide build` |
| `mvn test`, `gradle test` | `elide test` |
| `gradle run`, `mvn exec:java` | `elide run` |
| Maven goals on an existing `pom.xml` | `elide mvn -- package`; see [Native Maven](https://elide.help/docs/toolchain/jvm/native-maven). |
| Migrate `./gradlew` or `mvn` builds | `elide adopt`; see [Adopt an Existing Project](https://elide.help/docs/toolchain/usage/adopt). |
| `native-image` | `elide native-image -- -cp app.jar com.example.Main` |
| `google-java-format` | `elide format` |
| IDE project import | `elide project export --format=intellij` or `--format=pom` |

## Benchmarks

No benchmarks are published for JVM programs in 1.6.0. For ahead-of-time builds, see
[Native Image](https://elide.help/docs/toolchain/jvm/native-image).

## Strengths

- One binary replaces the JDK, Maven resolver, JUnit launcher and Google Java Format.
- `elide.pkl` declares dependencies, tests and artifacts without plugins.
- Annotation processors run in `elide build` and `elide javac` from a `processors` bucket.

## Weaknesses

- No Gradle support: `elide build` does not read `build.gradle` or `build.gradle.kts`, and Gradle plugins have no
  equivalent.
- `elide install -p .` does not merge POM parents or imported BOMs; versions inherited from a parent are dropped.
- No `jlink`, `jpackage` or `jshell` command, and JavaFX is not included.
- `elide adopt` is untested on multi-module and Android projects.
- javac jtreg tests: 99.9% pass (1 fail, 2 errors); see the [Compatibility Matrix](https://elide.help/docs/compatibility).
- JDK tool arguments go after `--`: `elide javac -d out Main.java` exits `2`.

## Next steps

- [Java and Kotlin with Elide](https://elide.help/docs/jvm)
- [JVM APIs](https://elide.help/docs/api-jvm)
- [Adopt an Existing Project](https://elide.help/docs/toolchain/usage/adopt)
- [JVM Toolchain](https://elide.help/docs/toolchain/jvm)
