Documentation menu

Read and decompile a JAR from the terminal with jdx

Decompile a jar from the command line: list its classes, read one method, and view source. jdx is a javap alternative that returns only what you asked for.

Pass a .jar on disk, a Maven coordinate, or a JDK class. jdx needs Java 21 or later, runs on Linux, macOS, and Windows, and is Apache-2.0. Text is the default, and every command accepts --json. An ambiguous reference exits 2 and lists every candidate; jdx does not guess. Install it with the one-line installer, then try the quickstart. Every command output on this page was produced by running that command when the page was built.

A Minecraft mod jar is the same workflow, pointed at the mapped jar your build already wrote. See Minecraft mods.

List what is in a jar#

jdx tree prints the package tree of one artifact. jdx ls lists the types in one package. jdx members lists what you can call on one class.

A file you already have is --jars (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.

jdx tree 'app*' --depth 2 --counts --jars path/to/app.jar --no-jdk
jdx ls com.example --jars path/to/app.jar --no-jdk
jdx members com.example.App --declared --kind method --limit 20 --jars path/to/app.jar --no-jdk

Run here against Gson 2.14.0. members is narrowed with --grep toJson; the next section opens one of those overloads. --fetch allows a download when the coordinate is not already in ~/.gradle/caches or ~/.m2. Each --coord example on this page passes it, so any one of them can be copied on its own. A coordinate is not downloaded without that flag.

jdx tree 'gson*' --depth 2 --counts --coord com.google.code.gson:gson:2.14.0 --fetch --no-jdk
package tree for 'gson*'
gson-2.14.0.jar
  com (221 types)
    com.google (221 types)
      com.google.gson (221 types)
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
jdx ls com.google.gson.stream --coord com.google.code.gson:gson:2.14.0 --fetch --no-jdk
types in package 'com.google.gson.stream'
  package com.google.gson.stream (7 types)
  class com.google.gson.stream.JsonReader  gson-2.14.0.jar
  class com.google.gson.stream.JsonReader$1  gson-2.14.0.jar
  class com.google.gson.stream.JsonScope  gson-2.14.0.jar
  enum com.google.gson.stream.JsonToken  gson-2.14.0.jar
  class com.google.gson.stream.JsonWriter  gson-2.14.0.jar
  class com.google.gson.stream.MalformedJsonException  gson-2.14.0.jar
  interface com.google.gson.stream.package-info  gson-2.14.0.jar
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
jdx members com.google.gson.Gson --declared --kind method --grep toJson --coord com.google.code.gson:gson:2.14.0 --fetch
members of com.google.gson.Gson
methods declared on com.google.gson.Gson:
  method public com.google.gson.JsonElement toJsonTree(java.lang.Object src)
  method public com.google.gson.JsonElement toJsonTree(java.lang.Object src, java.lang.reflect.Type typeOfSrc)
  method public java.lang.String toJson(com.google.gson.JsonElement jsonElement)
  method public java.lang.String toJson(java.lang.Object src)
  method public java.lang.String toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc)
  method public void toJson(com.google.gson.JsonElement jsonElement, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException
  method public void toJson(com.google.gson.JsonElement jsonElement, java.lang.Appendable writer) throws com.google.gson.JsonIOException
  method public void toJson(java.lang.Object src, java.lang.Appendable writer) throws com.google.gson.JsonIOException
  method public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException
  method public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, java.lang.Appendable writer) throws com.google.gson.JsonIOException
source: gson-2.14.0.jar (bytecode)
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)

Real output — this example ran against the current jdx when the page was built.

--declared is only the type's own members. Inherited members are the default. A longer list takes --limit, and the footer names the flag that shows the rest.

Reference: tree, ls, members. Filters are in Reading code.

Show one method body#

jdx body prints one method, not the class. 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 (226×), and the full Gson.java is 58,251 bytes (218×). That is the README benchmark; reproduce it with docs/bench-compare.sh.

jdx body 'com.google.gson.Gson#toJson(Object)' --coord com.google.code.gson:gson:2.14.0 --fetch
com.google.gson.Gson#toJson(java.lang.Object)
  source: gson-2.14.0-sources.jar · com/google/gson/Gson.java:542-547
  public String toJson(Object src) {
    if (src == null) {
      return toJson(JsonNull.INSTANCE);
    }
    return toJson(src, src.getClass());
  }
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)

Real output — this example ran against the current jdx when the page was built.

toJson has several overloads. jdx will not pick one. It exits 2 and prints every candidate as a reference you can paste:

jdx body 'com.google.gson.Gson#toJson' --coord com.google.code.gson:gson:2.14.0 --fetch
ambiguous: 8 candidates for com.google.gson.Gson#toJson
  com.google.gson.Gson#toJson(com.google.gson.JsonElement)
  com.google.gson.Gson#toJson(com.google.gson.JsonElement, com.google.gson.stream.JsonWriter)
  com.google.gson.Gson#toJson(com.google.gson.JsonElement, java.lang.Appendable)
  com.google.gson.Gson#toJson(java.lang.Object)
  com.google.gson.Gson#toJson(java.lang.Object, java.lang.Appendable)
  com.google.gson.Gson#toJson(java.lang.Object, java.lang.reflect.Type)
  com.google.gson.Gson#toJson(java.lang.Object, java.lang.reflect.Type, com.google.gson.stream.JsonWriter)
  com.google.gson.Gson#toJson(java.lang.Object, java.lang.reflect.Type, java.lang.Appendable)
hint: re-run with one of the refs above
[exit 2]

Real output — this example ran against the current jdx when the page was built.

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

Reference: body. The ref grammar is Symbol references.

Read source, or decompile#

jdx source and jdx body 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. A sources jar with a different file name is not paired. --fetch downloads the -sources.jar with the binary.

With sources paired, the answer is the real file, with its path and line range:

jdx source com.google.gson.JsonNull --lines 17:45 --coord com.google.code.gson:gson:2.14.0 --fetch
com.google.gson.JsonNull
  source: gson-2.14.0-sources.jar · com/google/gson/JsonNull.java:17-45
package com.google.gson;

/**
 * A class representing a JSON {@code null} value.
 *
 * @author Inderjeet Singh
 * @author Joel Leitch
 * @since 1.2
 */
public final class JsonNull extends JsonElement {
  /**
   * Singleton for {@code JsonNull}.
   *
   * @since 1.8
   */
  public static final JsonNull INSTANCE = new JsonNull();

  /**
   * Creates a new {@code JsonNull} object.
   *
   * @deprecated Deprecated since Gson version 1.8, use {@link #INSTANCE} instead.
   */
  @Deprecated
  public JsonNull() {
    // Do nothing
  }

  /**
   * Returns the same instance since it is an immutable value.
next: jdx show com.google.gson.JsonNull
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)

Real output — this example ran against the current jdx when the page was built.

Without a paired sources jar, jdx decompiles with Vineflower and labels the result ⚠ reconstructed, naming the engine and the jar. Slice a long file with --lines A:B or --around '<canonical ref>' --context N instead of reading all of it.

jdx body 'java.util.HashMap#get(java.lang.Object)'
java.util.HashMap#get(java.lang.Object)
  source: src.zip · java.base/java/util/HashMap.java:562-565
    public V get(Object key) {
        Node<K,V> e;
        return (e = getNode(key)) == null ? null : e.value;
    }
next: jdx show java.util.HashMap

Real output — this example ran against the current jdx when the page was built.

--engine javap prints raw bytecode 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.

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)

Real output — this example ran against the current jdx when the page was built.

members and signature always come from bytecode, so those lists stay exact with or without sources. When sources and bytecode disagree, jdx warns SOURCES_VERSION_MISMATCH and bytecode wins for structure. Kotlin binaries are read from @Metadata. Reading .kt sources needs a one-time jdx kotlin install, which is one of the few commands that uses the network. See Reading code.

Reference: source, body.

Look inside non-class contents#

These read the jar as a zip of entries. They do not decompile classes.

jdx manifest lists META-INF/MANIFEST.MF main attributes (Main-Class, Implementation-Version, Multi-Release, and the rest). jdx resources lists non-class paths; --cat prints the text of the unique match. jdx services lists META-INF/services providers. jdx literals searches string constants: bytecode LDC loads, String field constants, and .properties keys and values.

jdx manifest Multi-Release --coord com.google.code.gson:gson:2.14.0 --fetch --no-jdk
manifests matching 'Multi-Release'
gson-2.14.0.jar (1)
  Multi-Release: true
jdx resources META-INF/MANIFEST.MF --cat --coord com.google.code.gson:gson:2.14.0 --fetch --no-jdk
META-INF/MANIFEST.MF
  artifact: gson-2.14.0.jar
  size: 1243 bytes
Manifest-Version: 1.0
Created-By: Maven JAR Plugin 3.5.0
Java-Version: 8
Build-Jdk-Spec: 17
Bundle-ContactAddress: https://github.com/google/gson
Bundle-Description: Gson JSON library
Bundle-Developers: google;organization=Google;organizationUrl="https://w
 ww.google.com"
Bundle-DocURL: https://github.com/google/gson
Bundle-License: "Apache-2.0";link="https://www.apache.org/licenses/LICEN
 SE-2.0.txt"
Bundle-ManifestVersion: 2
Bundle-Name: Gson
… 16 more lines (run it yourself to see them all)
jdx literals 'com.google.gson' --coord com.google.code.gson:gson:2.14.0 --fetch --limit 5 --no-jdk
literals matching 'com.google.gson'
gson-2.14.0.jar (2)
  ldc com.google.gson.internal.bind.TypeAdapters#javaTimeTypeAdapterFactory()  "com.google.gson.internal.bind.JavaTimeTypeAdapters"  TypeAdapters.java:951
  ldc com.google.gson.internal.reflect.ReflectionHelper#getInaccessibleTroubleshootingSuffix(java.lang.Exception)  "to module com.google.gson"  ReflectionHelper.java:51
jdx services java.sql.Driver --coord org.postgresql:postgresql:42.7.4 --fetch --no-jdk
services matching 'java.sql.Driver'
postgresql-42.7.4.jar (1)
  service java.sql.Driver
    provider org.postgresql.Driver

Real output — this example ran against the current jdx when the page was built.

Two or more --cat matches exit 2 and list path --in artifact candidates. Tighten the pattern, or add --in, then --cat that one path. Binary payloads are not dumped. Nothing matched exits 1. The PostgreSQL coordinate is a separate artifact from Gson, so that command passes --fetch as well.

Reference: manifest, resources, services, literals.

Maven coordinates and JDK classes#

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.

jdx members java.util.HashMap --limit 5
members of java.util.HashMap
constructors declared on java.util.HashMap:
  constructor public HashMap()
  constructor public HashMap(int initialCapacity)
  constructor public HashMap(int initialCapacity, float loadFactor)
  constructor public HashMap(java.util.Map<? extends K, ? extends V> m)
methods declared on java.util.HashMap:
  method public V compute(K key, java.util.function.BiFunction<? super K, ? super V, ? extends V> remappingFunction)
+ 7 from java.lang.Object (--from java.lang.Object to expand)
5 of 53 members shown (--limit 53 to see more)
source: java.base (jrt)
jdx show com.google.gson.Gson --coord com.google.code.gson:gson:2.14.0 --fetch
class com.google.gson.Gson
  public final class Gson
  extends java.lang.Object
  members: 2 constructors, 33 methods, 26 fields
source: gson-2.14.0.jar (bytecode)
next: jdx members com.google.gson.Gson --inherited
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)

Real output — this example ran against the current jdx when the page was built.

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. See Classpath & workspaces.

Nothing in the jar runs#

Bytecode is parsed with ASM. Inspected classes are never loaded, so no static initialiser and no other code from the jar runs. jdx writes only inside its own cache, config, and runtime directories. --jars reads the file you named and does not download it.

Using it from an AI agent#

jdx mcp is the stdio server: 27 typed tools, one per query, so the agent does not quote # and (. jdx setup writes that server into the agent you name. The server itself never downloads; prime a missing coordinate with the CLI --fetch first.

jdx setup --agent claude-code --scope project
jdx setup --agent cursor --scope project
jdx setup --agent codex --scope project
jdx mcp

--scope project writes into the current checkout. --scope system writes the user-global file. The same command covers other agents. Per-agent pages: integrations, Claude Code, Cursor, Codex.

jdx setup --agent claude-code --scope project --check
claude-code project setup not installed
  ./.mcp.json
  detected: claude-code not found on PATH
next: jdx setup --agent claude-code --scope project
[exit 1]

Real output — this example ran against the current jdx when the page was built.

--check exits 1 when jdx is not wired yet and 0 when it is. The tool list is on the MCP tools page. Wiring details and the CLI cheat sheet are in Use with AI agents.

Reference: setup, mcp.

jdx vs unzip + javap#

Task unzip + javap jdx
List what is in a jar unzip -l, then pick a .class path jdx tree, jdx ls, jdx members
One method javap -c prints the whole class (60,590 bytes for Gson) jdx body prints that method (267 bytes, 226× smaller)
The source file unzip -p dumps Gson.java (58,251 bytes) jdx body or jdx source returns the member or a line range
No -sources.jar run a decompiler yourself Vineflower, labelled ⚠ reconstructed; jdx body --engine javap for bytecode
Manifest, resources, services, strings unzip -p and grep jdx manifest, jdx resources --cat, jdx services, jdx literals
Several overloads you choose exit 2, and every candidate is printed

Every command accepts --json. Exit codes are in Output, JSON & exit codes.

Where next#

Edit this page on GitHub · View as Markdown · Updated