Read Javadoc from a jar in the terminal
Read the Javadoc of a class or method in a jar, a Maven dependency, or the JDK from the terminal. jdx doc prints that comment for you and for AI agents.
The comment usually lives in an HTML tree, or behind a hover in an IDE. jdx doc prints it as plain text, plus the file and the line range it came from. HTML from a known set of tags is stripped. Block tags such as @param and @return stay. An inline tag is unwrapped when its closing } is on the same line. 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 with the one-line installer. Every command output on this page was produced by running that command when the page was built.
Finding which file holds the class is Find which JAR contains a class. Opening the method body is Read and decompile a JAR from the terminal.
Read the Javadoc of a class#
jdx doc takes a type or a member reference. A type prints that class's own comment. The first line is the canonical reference. The source: line names the sources file, the path inside it, and the line range. The full answer closes with next: jdx show and the declaring type.
Run here against Gson 2.14.0. Gson's comments wrap some {@link} tags across lines, so those tags stay partly written in the text. A tag that fits on one line is unwrapped. --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. --fetch also downloads the -sources.jar when the repository publishes one. A repository with no -sources.jar still returns the binary.
jdx doc com.google.gson.Gson --coord com.google.code.gson:gson:2.14.0 --fetch
com.google.gson.Gson
source: gson-2.14.0-sources.jar · com/google/gson/Gson.java:49-134
This is the main class for using Gson. Gson is typically used by first constructing a Gson
instance and then invoking #toJson(Object) or Class) methods on
it. Gson instances are Thread-safe so you can reuse them freely across multiple threads.
You can create a Gson instance by invoking new Gson() if the default configuration is
all you need. You can also use GsonBuilder to build a Gson instance with various
configuration options such as versioning support, pretty printing, custom newline, custom indent,
custom JsonSerializers, JsonDeserializers, and InstanceCreators.
Here is an example of how Gson is used for a simple Class:
Gson gson = new Gson(); // Or use new GsonBuilder().create();
MyType target = new MyType();
… 72 more lines (run it yourself to see them all)Real output — this example ran against the current jdx when the page was built.
The class comment is long. --max-lines caps the text (default 200) and the footer names the limit that shows the rest. --json carries the same text, the line range, and the provenance. Gson 2.14.0 is a multi-release jar, so jdx warns MULTI_RELEASE_VARIANT and still prints the comment.
Reference: doc.
Read the Javadoc of one method#
toJson has several overloads. jdx will not pick one. It exits 2 and prints every candidate as a reference you can paste:
jdx doc '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.
jdx doc '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:527-541
This method serializes the specified object into its equivalent JSON representation. This
method should be used when the specified object is not a generic type. This method uses {@link
Class#getClass()} to get the type for the specified object, but the getClass() loses
the generic type information because of the Type Erasure feature of Java. Note that this method
works fine if any of the object fields are of generic type, just the object itself should not
be of a generic type. If the object is of generic type, use Type)
instead. If you want to write out the object to a Writer, use {@link #toJson(Object,
Appendable)} instead.
@param src the object for which JSON representation is to be created
@return JSON representation of src.
@see #toJson(Object, Appendable)
@see #toJson(Object, Type)
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.
A method with no comment of its own falls back to the nearest documenting supertype. The source: line then names that supertype as (inherited from …), and the file and line range are the supertype's comment. {@inheritDoc} inside a comment that does exist is filled from that supertype's first paragraph. Fields and constructors do not inherit a comment. A type does not inherit its superclass's class comment.
java.util.Collections$UnmodifiableMap is a nested JDK class, so the $ is part of the reference. Its get method has no comment of its own. The line below names java.util.Map:
jdx doc 'java.util.Collections$UnmodifiableMap#get(Object)'
java.util.Collections$UnmodifiableMap#get(java.lang.Object)
source: src.zip · java.base/java/util/Map.java:217-240 (inherited from java.util.Map)
Returns the value to which the specified key is mapped,
or null if this map contains no mapping for the key.
More formally, if this map contains a mapping from a key
k to a value v such that
Objects.equals(key, k),
… 17 more lines (run it yourself to see them all)Real output — this example ran against the current jdx when the page was built.
--no-inherited keeps only the comment written on that exact symbol. --inherited is the default and is accepted for explicitness. Passing --inherited and --no-inherited together exits 3. --raw prints the comment verbatim, delimiters already removed and the leading stars kept, instead of the rendered plain text.
The reference grammar is Symbol references. A package or module reference exits 3. A missing symbol exits 1 and prints did-you-mean suggestions.
A JDK class#
The running JDK is on the classpath with no coordinate and no --fetch. When that JDK ships lib/src.zip, the comment is read from it. The sources file on the source: line is src.zip.
jdx doc 'java.util.Map#get(Object)'
java.util.Map#get(java.lang.Object)
source: src.zip · java.base/java/util/Map.java:217-240
Returns the value to which the specified key is mapped,
or null if this map contains no mapping for the key.
More formally, if this map contains a mapping from a key
k to a value v such that
Objects.equals(key, k),
then this method returns v; otherwise
it returns null. (There can be at most one such mapping.)
If this map permits null values, then a return value of
null does not necessarily indicate that the map
contains no mapping for the key; it's also possible that the map
explicitly maps the key to null. The {@link #containsKey
containsKey} operation may be used to distinguish these two cases.
… 9 more lines (run it yourself to see them all)Real output — this example ran against the current jdx when the page was built.
A JDK distribution that omits lib/src.zip exits 1. The message names the class and the module (java.base for java.util.Map) and says decompilation is not yet implemented. A library jar with no paired sources prints the same kind of message. That case is next.
--no-jdk leaves the JDK out. With --no-jdk, no --jars, no --coord, and no selected workspace, jdx doc exits 4.
show, members, and signature#
jdx show prints the class card: kind, modifiers, supertypes, and member counts. jdx members lists what you can call. jdx members --with-doc adds the first sentence of each member's javadoc when a sources comment exists. jdx signature prints one declaration line per overload. Structure comes from bytecode, so that list is the same with or without a sources jar. jdx body prints the method. jdx body --with-doc places the javadoc beside that body when sources have a comment.
jdx members com.google.gson.Gson --declared --kind method --grep '^toJson$' --with-doc --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 java.lang.String toJson(com.google.gson.JsonElement jsonElement) — Converts a tree of JsonElements into its equivalent JSON representation.
method public java.lang.String toJson(java.lang.Object src) — This method serializes the specified object into its equivalent JSON representation.
method public java.lang.String toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc) — This method serializes the specified object, including those of generic types, into its equivalent JSON representation.
method public void toJson(com.google.gson.JsonElement jsonElement, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException — Writes the JSON for jsonElement to writer.
method public void toJson(com.google.gson.JsonElement jsonElement, java.lang.Appendable writer) throws com.google.gson.JsonIOException — Writes out the equivalent JSON for a tree of JsonElements.
method public void toJson(java.lang.Object src, java.lang.Appendable writer) throws com.google.gson.JsonIOException — This method serializes the specified object into its equivalent JSON representation and writes it to the writer.
method public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, com.google.gson.stream.JsonWriter writer) throws com.google.gson.JsonIOException — Writes the JSON representation of src of type typeOfSrc to writer.
method public void toJson(java.lang.Object src, java.lang.reflect.Type typeOfSrc, java.lang.Appendable writer) throws com.google.gson.JsonIOException — This method serializes the specified object, including those of generic types, into its equivalent JSON representation and writes it to the writer.
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)
jdx signature 'com.google.gson.Gson#toJson(Object)' --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)
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)Real output — this example ran against the current jdx when the page was built.
Reference: show, members, signature, body. The rest of reading one class is Reading code. The method body, with or without a sources jar, is Read and decompile a JAR from the terminal.
Where the text comes from#
Javadoc comments are not stored in the class file. jdx doc reads them from paired sources.
For foo.jar, the pair 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. A binary jar that itself contains .java or .kt entries is its own pair. The JDK pair is lib/src.zip.
A group:artifact:version coordinate resolves from ~/.gradle/caches and ~/.m2 first. --fetch downloads a missing artifact into the jdx cache (<cache-dir>/m2, ~/.cache/jdx/m2 on Linux) with checksum verification, and downloads the -sources.jar alongside when the repository publishes one. --repo adds a repository tried before Maven Central. The CLI contacts the network only when you pass --fetch, or when you run jdx upgrade or jdx kotlin install. A coordinate that is not in the local caches, and was not given --fetch, exits 5 and the message names --fetch.
A file you already have is --jars (a jar, a class directory, or a glob). Quote the glob so the shell does not expand it. An unquoted expansion exits 3.
jdx doc com.example.App --jars path/to/app.jar --no-jdk
jdx doc 'com.example.App#run()' --jars 'libs/*.jar' --no-jdkWhen the class is in that jar and no sources are paired, jdx doc exits 1. The text names the class and the jar file:
not found: com.example.App
no sources for com.example.App in app.jar (decompilation not yet implemented, T-026)The parenthetical is the tool's own words. A reconstructed class file has no javadoc comment in it, so jdx doc stops there. jdx body and jdx source on the same reference decompile with Vineflower and label the result ⚠ reconstructed. jdx members and jdx signature still answer from bytecode. jdx members --with-doc leaves the sentence off when there is no sources comment.
Maven also publishes a *-javadoc.jar of HTML pages. jdx doc reads the comment in the paired -sources.jar, which is the text those pages were generated from.
A member that exists in bytecode and has no counterpart in the sources exits 1, and the message names SOURCES_VERSION_MISMATCH. When the comment is found and the sources jar disagrees about other members, the comment is still printed and jdx warns SOURCES_VERSION_MISMATCH. Bytecode stays the authority for which members exist.
Kotlin binaries still answer jdx members and jdx signature from @Metadata. KDoc is read from .kt sources, which needs a one-time jdx kotlin install. A class whose sources are Kotlin only, with that sidecar absent, exits 1 and the message names jdx kotlin install. Suspend, nullability, and file facades are Read a Kotlin library API from a compiled jar.
Inside a Gradle or Maven project, with no classpath flags, jdx discovers project classes and the dependency jars named in the build files. It never runs Gradle or Maven to do that. See Classpath & workspaces.
From an AI agent#
The same question is the MCP tool jdx_doc. jdx mcp does not take a jar path or a Maven coordinate on the call, and it does not auto-discover a project. Create a workspace with the CLI, then start the server on it. A tool call may pass workspace to pick another stored name. The server never downloads. Prime a coordinate with --fetch first, or pass files you already have.
jdx doc com.google.gson.Gson --coord com.google.code.gson:gson:2.14.0 --fetch
jdx ws create gson --coord com.google.code.gson:gson:2.14.0
jdx mcp -w gson
jdx setup --agent claude-code --scope project
jdx setup --agent cursor --scope project
jdx setup --agent codex --scope projectjdx setup writes args as mcp only. Add -w by hand when the workspace is not default. The config shapes are in An MCP server for Java and Kotlin bytecode.
jdx_doc takes query (a type or a member, such as com.google.gson.Gson or com.google.gson.Gson#toJson(Object)), workspace, inherited (default true), no-inherited, raw, and maxLines (default 200). Setting inherited and no-inherited together is code 3. An ambiguous member is code 2 and lists every candidate. No paired sources is code 1. jdx serve answers the same JSON at GET /v1/doc?query=….
Bytecode is parsed with ASM. Inspected classes are never loaded, so no static initialiser from the jar runs. jdx writes only inside its own cache, config, and runtime directories.
FAQ#
How do I read Javadoc from a jar in the terminal?#
jdx doc com.example.App --jars path/to/app.jar prints that class's javadoc. jdx doc 'com.example.App#run(String)' prints one method. The text comes from a paired -sources.jar. Install jdx with the one-line installer. Java 21 or later is required.
How do I view Javadoc for a Maven dependency from the command line?#
jdx doc com.google.gson.Gson --coord com.google.code.gson:gson:2.14.0 --fetch resolves the coordinate from ~/.gradle/caches and ~/.m2 first. --fetch is what allows a download, including the -sources.jar. Without --fetch, a coordinate that is not already cached exits 5 and the message names --fetch.
How do I read Gson Javadoc for toJson without an IDE?#
jdx doc 'com.google.gson.Gson#toJson(Object)' --coord com.google.code.gson:gson:2.14.0 --fetch prints that overload. The bare name com.google.gson.Gson#toJson exits 2 and lists every overload.
What happens when a library jar has no sources jar?#
jdx doc exits 1 and reports no sources for … (decompilation not yet implemented, T-026). jdx members and jdx signature still print the declaration from bytecode. jdx body decompiles the method with Vineflower and labels it ⚠ reconstructed. The javadoc comment itself is only in the sources.
Can an AI agent read Javadoc from a library jar?#
jdx_doc is the MCP tool, and its answer matches jdx doc. jdx setup --agent cursor --scope project wires the server for Cursor. The same command takes claude-code and codex. The server does not download. Run the coordinate once with --fetch, or create a workspace with --jars, before the agent calls the tool.
Where next#
jdx doc— every flag, generated from the binary.- Find which JAR contains a class — which file holds a class, and the classes in one jar.
- Read and decompile a JAR from the terminal — one method, source, or a decompilation.
- Read a Kotlin library API from a compiled jar — suspend, nullability, and properties from
@Metadata. - Installation — Linux, macOS, Windows, and offline installs.
- Reading code —
show,members,signature,doc, andbody. - Symbol references — how to paste a canonical ref.
- Classpath & workspaces —
--jars,--coord, andjdx ws. - Output, JSON & exit codes — the exit-code table.
- Command catalogue — every flag.