# A javap alternative for reading class files and jars

jdx is a javap alternative for reading class file signatures, one method, callers, and implementors from a jar, a coordinate, or the JDK.

javap disassembles a class file. jdx answers the question you would otherwise build out of `javap`, `unzip`, and `grep`, and it stops at the member you named. Text is the default. Every command accepts `--json`. An ambiguous reference exits 2 and lists every candidate. jdx does not guess. Install with the [one-line installer](https://mohammadmd1383.github.io/jdx/docs/installation/), then try the [quickstart](https://mohammadmd1383.github.io/jdx/docs/quickstart/). Every command output on this page was produced by running that command when the page was built.

## What javap prints

`javap` takes a classpath and a class name. `javap -public -classpath app.jar com.example.App` prints that class's public members. `javap -c -p` prints the bytecode of every method in the class, private methods included. `javap -v` adds the constant pool and the attributes. The unit of output is the whole class.

That listing is the right tool when you want the constant pool or a verbose attribute dump of one class file. javap does not search other classes, list callers, list implementors, decompile to Java source, or diff two versions of a jar.

## What jdx adds on the same file

Pass the jar, a class directory, a Maven coordinate, or a JDK class. The commands below are the ones a `javap` session usually turns into.

|Question|javap|jdx|
|---|---|---|
|Members of one class|`javap -public -classpath app.jar com.example.App` prints the class|`jdx members com.example.App --declared --jars app.jar`|
|One method's signature|the class listing, or `javap -s` for JVM descriptors|`jdx signature 'com.example.App#run'` prints each overload with parameter names|
|Bytecode of one method|`javap -c` prints every method|`jdx body 'com.example.App#run()' --engine javap --jars app.jar`|
|Java source|javap disassembles; it does not decompile|paired `-sources.jar`, or Vineflower labelled `⚠ reconstructed`|
|A name somewhere in the jar|you choose the class first|`jdx search`|
|Who calls it, who implements it|not a javap question|`jdx callers`, `jdx implementors`|
|What changed between two jars|not a javap question|`jdx diff`|

`--jars` takes a jar, a class directory, or a glob. Quote globs so the shell does not expand them; an unquoted expansion exits 3. `--no-jdk` leaves the JDK out when the question is about that jar alone.

## Read class file signatures

`jdx members` lists what you can call. `jdx signature` prints one member: each overload, with parameter names, generics, `throws`, and defaults. Both come from bytecode parsed with ASM, so the signatures stay exact with or without a sources jar. A name without a parameter list lists every overload and exits 0. `jdx body` on that same name exits 2 and prints every candidate as a reference you can paste. A type reference passed to `signature` exits 3; that command wants a member.

```console jdx-generated
$ jdx members java.util.HashMap --declared --kind method --limit 6
members of java.util.HashMap
methods declared on java.util.HashMap:
  method public V compute(K key, java.util.function.BiFunction<? super K, ? super V, ? extends V> remappingFunction)
  method public V computeIfAbsent(K key, java.util.function.Function<? super K, ? extends V> mappingFunction)
  method public V computeIfPresent(K key, java.util.function.BiFunction<? super K, ? super V, ? extends V> remappingFunction)
  method public V get(java.lang.Object key)
  method public V getOrDefault(java.lang.Object key, V defaultValue)
  method public V merge(K key, V value, java.util.function.BiFunction<? super V, ? super V, ? extends V> remappingFunction)
6 of 25 members shown (--limit 25 to see more)
source: java.base (jrt)
$ jdx signature 'java.util.HashMap#get'
signatures of java.util.HashMap#get
  public V get(java.lang.Object key)
source: java.base (jrt)
next: jdx show java.util.HashMap
```

The same question against a library jar. `--fetch` allows a download when the coordinate is not already in `~/.gradle/caches` or `~/.m2`.

```console jdx-generated
$ jdx signature 'com.google.gson.Gson#toJson' --coord com.google.code.gson:gson:2.14.0 --fetch
signatures of com.google.gson.Gson#toJson
  public java.lang.String toJson(java.lang.Object src)
  public java.lang.String toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc)
  public void toJson(java.lang.Object src, java.lang.Appendable writer) throws com.google.gson.JsonIOException
  public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, java.lang.Appendable writer) throws com.google.gson.JsonIOException
  public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException
  public java.lang.String toJson(com.google.gson.JsonElement jsonElement)
  public void toJson(com.google.gson.JsonElement jsonElement, java.lang.Appendable writer) throws com.google.gson.JsonIOException
  public void toJson(com.google.gson.JsonElement jsonElement, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException
source: gson-2.14.0.jar (bytecode)
next: jdx show com.google.gson.Gson
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
```

Always quote references in a shell: `#`, `(`, and `$` are shell syntax. Paste one of the printed refs into the next command. Do not retype parameter types by hand.

Reference: [`members`](https://mohammadmd1383.github.io/jdx/docs/reference/members/), [`signature`](https://mohammadmd1383.github.io/jdx/docs/reference/signature/). The ref grammar is [Symbol references](https://mohammadmd1383.github.io/jdx/docs/symbol-references/). Filters are in [Reading code](https://mohammadmd1383.github.io/jdx/docs/reading-code/#what-can-i-call-members-and-outline).

## Search, callers, and implementors

These have no `javap` equivalent. `search` finds a name across the classpath. Default `--kind all` covers types, packages, and modules. Pass `--kind method` or `--kind field` to scan members. `implementors` lists who implements an interface or extends a class. `callers` is override-aware by default; `--exact` keeps invoke-owner matching. Constructors, static methods, and private methods stay exact either way.

```console jdx-generated
$ jdx search '*Http*Client' --kind class --limit 8
search results for '*Http*Client'
  class java.net.http.HttpClient  java.net.http
  class sun.net.www.http.HttpClient  java.base
  class sun.net.www.protocol.https.HttpsClient  java.base
$ jdx implementors com.google.gson.TypeAdapter --limit 6 --coord com.google.code.gson:gson:2.14.0 --fetch --no-jdk
hierarchy of 'com.google.gson.TypeAdapter'
  subtypes in workspace (6)
    class com.google.gson.Gson$FutureTypeAdapter  gson-2.14.0.jar (extends com.google.gson.internal.bind.SerializationDelegatingTypeAdapter)
    class com.google.gson.TypeAdapter$NullSafeTypeAdapter  gson-2.14.0.jar
    class com.google.gson.internal.Excluder$1  gson-2.14.0.jar
    class com.google.gson.internal.bind.ArrayTypeAdapter  gson-2.14.0.jar
    class com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter  gson-2.14.0.jar
    class com.google.gson.internal.bind.DefaultDateTypeAdapter  gson-2.14.0.jar
6 of 66 subtypes shown (--limit 66 to see more)
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
$ jdx callers 'com.google.gson.JsonArray#add(com.google.gson.JsonElement)' --limit 5 --coord com.google.code.gson:gson:2.14.0 --fetch --no-jdk
callers of 'com.google.gson.JsonArray#add(com.google.gson.JsonElement)'
  call com.google.gson.JsonArray#deepCopy()  gson-2.14.0.jar
  call com.google.gson.internal.bind.JsonElementTypeAdapter#read(com.google.gson.stream.JsonReader)  gson-2.14.0.jar
  call com.google.gson.internal.bind.JsonTreeWriter#put(com.google.gson.JsonElement)  gson-2.14.0.jar
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
```

`callers` only accepts methods and constructors. A type or field ref exits 3. Nothing matched exits 1. `Gson#toJson(Object)` has no call sites inside gson-2.14.0, so the example above uses `JsonArray#add(JsonElement)`, which three methods in that jar call.

Reference: [`search`](https://mohammadmd1383.github.io/jdx/docs/reference/search/), [`implementors`](https://mohammadmd1383.github.io/jdx/docs/reference/implementors/), [`callers`](https://mohammadmd1383.github.io/jdx/docs/reference/callers/). More of the graph is in [Usages, hierarchy \& calls](https://mohammadmd1383.github.io/jdx/docs/navigating-code/#call-hierarchy-callers-and-calls).

## Decompile with Vineflower, or stay on bytecode

`jdx body` and `jdx source` prefer a paired `-sources.jar`. For `foo.jar` that is a sibling `foo-sources.jar`, or the same file name in the Gradle or Maven cache layout under that version. `--fetch` downloads the `-sources.jar` with the binary.

With no pair, jdx decompiles with Vineflower and labels the result `⚠ reconstructed`, naming the engine and the jar. `--engine javap` prints the raw bytecode of that one member instead. `--engine vineflower` forces a reconstruction even when sources are paired. When Vineflower returns only a `$VF: Could not decompile…` stub, the default ladder falls through to `javap` instead of serving the stub.

```console jdx-generated
$ jdx body 'java.util.HashMap#get(java.lang.Object)' --engine javap
java.util.HashMap#get(java.lang.Object)
  source: disassembled by javap from java.base · java/util/HashMap.java:346-359  ⚠ reconstructed
  public V get(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Ljava/lang/Object;
    Code:
       0: aload_0
       1: aload_1
       2: invokevirtual #158                // Method getNode:(Ljava/lang/Object;)Ljava/util/HashMap$Node;
       5: dup
       6: astore_2
       7: ifnonnull     14
      10: aconst_null
… 5 more lines (run it yourself to see them all)
```

On gson-2.14.0 the body of `com.google.gson.Gson#toJson(Object)` alone is 267 bytes. `javap -c` of that whole class is 60,590 bytes, and the full `Gson.java` is 58,251 bytes. That measurement is the [README benchmark](https://github.com/MohammadMD1383/jdx/blob/main/README.md). Reproduce it with [`docs/bench-compare.sh`](https://github.com/MohammadMD1383/jdx/blob/main/docs/bench-compare.sh). The walkthrough is [Read and decompile a JAR from the terminal](https://mohammadmd1383.github.io/jdx/docs/read-jar-from-terminal/).

Reference: [`body`](https://mohammadmd1383.github.io/jdx/docs/reference/body/), [`source`](https://mohammadmd1383.github.io/jdx/docs/reference/source/).

## Diff two jars

`jdx diff` compares the bytecode API of two artifacts. The two arguments are the jars, class directories, globs, or Maven coordinates. There is no `--jars` and no classpath. `--fail-on breaking` exits 1 when a breaking change is present and 0 otherwise. That is the one documented exception to the [exit-code table](https://mohammadmd1383.github.io/jdx/docs/output/#exit-codes). The verdict is also `result.gate` in `--json`.

```bash
jdx diff old.jar new.jar --fail-on breaking
jdx diff com.google.code.gson:gson:2.11.0 com.google.code.gson:gson:2.14.0 --severity breaking --fetch
```

The executed Gson comparison is on [API diff for upgrades](https://mohammadmd1383.github.io/jdx/docs/api-diff/).

jdx reads the names stored in the file. v1 does not read mapping files and does not rename classes. Pass the jar Fabric Loom or NeoForge ModDevGradle already wrote with `--jars` on the commands that take a classpath. `diff` only works within one mapping namespace: both sides must already use the same names. A Yarn jar diffed against a Mojmap jar looks like nearly every member was removed and re-added. Compare two Yarn jars, or two Mojmap jars, or two builds of your mod. See [Minecraft mods](https://mohammadmd1383.github.io/jdx/docs/minecraft-mods/).

Reference: [`diff`](https://mohammadmd1383.github.io/jdx/docs/reference/diff/).

## Jars, coordinates, and the JDK

The running JDK is on the classpath with no setup. A `group:artifact:version` coordinate resolves from `~/.gradle/caches` and `~/.m2` first. The CLI contacts the network only when you pass `--fetch`, or when you run `jdx upgrade` or `jdx kotlin install`. Inside a Gradle or Maven project, with no classpath flags, jdx discovers project classes and dependency jars from the build files and the local caches. It never runs Gradle or Maven to do that. The remapped Minecraft jar is usually not one of those coordinates, so pass it with `--jars`. See [Classpath \& workspaces](https://mohammadmd1383.github.io/jdx/docs/classpath/).

Bytecode is parsed with ASM. Inspected classes are never loaded, so no static initialiser from the jar runs.

From an agent, the same questions are tools on `jdx mcp`. See [An MCP server for Java and Kotlin bytecode](https://mohammadmd1383.github.io/jdx/docs/java-mcp-server/).

## Where next

- [Find which JAR contains a class](https://mohammadmd1383.github.io/jdx/docs/find-class-in-jar/) — which file holds a class, across a glob or a coordinate.
- [Read and decompile a JAR](https://mohammadmd1383.github.io/jdx/docs/read-jar-from-terminal/) — list a jar, open one method, decompile when there are no sources.
- [Reading code](https://mohammadmd1383.github.io/jdx/docs/reading-code/) — `show`, `outline`, `doc`, and search.
- [Help AI coding agents understand Java dependencies](https://mohammadmd1383.github.io/jdx/docs/reduce-agent-tokens-java/) — `outline` and `members` before a source dump.
- [Usages, hierarchy \& calls](https://mohammadmd1383.github.io/jdx/docs/navigating-code/) — the rest of the graph.
- [Command catalogue](https://mohammadmd1383.github.io/jdx/docs/reference/) — every flag.
