Safeguard
Developer Tools•

How do you find deprecated Java APIs before a JDK upgrade?

The JDK ships jdeprscan, a static tool that scans jars and classes for deprecated Java SE APIs. See how to run it, read it and what it cannot see.

Safeguard Security Team
4 min read

Run jdeprscan, the static analysis tool that ships with the JDK. It scans a jar, a directory of class files or a single class for uses of deprecated Java SE APIs. It only reports APIs defined by Java SE itself, so library deprecations need another check.

What the tool is

The Oracle documentation for Java SE 21 describes jdeprscan as a static analysis tool that scans a jar file or other aggregation of class files for uses of deprecated API elements. The arguments can be a directory, a jar, or a class name or class file.

Two limits are stated in the same page. First, the deprecated APIs it reports are only those defined by Java SE. Deprecated APIs defined by third party libraries are not reported. Second, the scanned classes must have their dependencies on the class path, or it prints an error for each missing class.

Running it

A basic scan of one jar:

jdeprscan my-service.jar

To resolve dependencies, pass the same class path your application uses:

jdeprscan --class-path "libs/*" my-service.jar

To focus on what will actually disappear, limit the scan to APIs deprecated for removal:

jdeprscan --for-removal --class-path "libs/*" my-service.jar

The documentation lists a list option too, which prints the set of deprecated APIs without scanning anything. The output names the class that uses the deprecated element and the element itself, in internal slash separated form.

OptionUse
class path optionMake dependent classes resolvable
for-removal optionShow only APIs marked for removal
list optionPrint deprecated APIs, no scan
verbose optionExtra output during processing

Reading the results

Not all findings are equal. Sort them:

  1. Deprecated for removal and in your own code: fix first, since a future JDK will break the build or the runtime.
  2. Deprecated for removal and inside a dependency: check for a newer release of that dependency.
  3. Plain deprecations in your own code: schedule them, they are usually easy.
  4. Plain deprecations in dependencies: note and monitor, since the dependency owner has to act.

Scanning your jar and your dependency jars separately makes ownership clear. A finding in a library you do not control becomes a ticket for an upgrade or an issue upstream.

What jdeprscan does not cover

The tool looks at API usage. It does not tell you about behavior changes that keep the same signature, such as stronger encapsulation of JDK internals or changed defaults. Those need a test run on the new JDK. Treat jdeprscan as one input beside running your tests on the target JDK in a branch and reading release notes for that version.

It also does not tell you about security. A clean scan says nothing about whether a dependency carries a known vulnerability.

A short upgrade routine

  1. Build your artifact and collect its dependency jars.
  2. Run jdeprscan with the for-removal option and save the output.
  3. Fix or ticket each finding, with owners.
  4. Run the test suite on the target JDK.
  5. Repeat the scan against the target release and compare.

Quick check

Does jdeprscan report deprecated methods in my third party libraries?

No. It reports deprecated Java SE APIs only. Library deprecations need other checks.

Why do I see cannot find class errors?

The scanned classes depend on classes missing from the class path. Pass the application class path.

Safeguard covers the dependency side with SBOM generation and vulnerability scanning for Java projects. Try the free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.