JDEPRSCAN(1)
π jdeprscan(1) β the JDK Commands glow-up π
okay so you're in the JDK Commands section of the manual and you found jdeprscan, and honestly? bestie, you picked a good one. this is the static analysis tool that scans a jar file (or some other aggregation of class files) for uses of deprecated API elements. no cap, it's the vibe-check for your dependencies π
β¨ NAME β¨
jdeprscan β static analysis tool that scans a jar file (or some other aggregation of class files) for uses of deprecated API elements π΅οΈββοΈ
πΈ SYNOPSIS πΈ
- **`options`** β see *Options for the jdeprscan Command* below, iykyk π
- **`dir|jar|class`** β the `jdeprscan` command scans *each* argument for usages of deprecated APIs. and like, the arguments can be a:
- **`dir`**: a directory π
- **`jar`**: a JAR file π«
- **`class`**: a class name or class file π§©
the class name should use a dot (`.`) as a separator. for example:
for nested classes, the dollar sign $ separator character should be used. for example:
a class file can also be named. for example:
π DESCRIPTION π
the jdeprscan tool is a static analysis tool provided by the JDK that scans a JAR file or some other aggregation of class files for uses of deprecated API elements. the deprecated APIs identified by the jdeprscan tool are only those that are defined by Java SE. deprecated APIs defined by third-party libraries? not reported, sorry bestie π
to scan a JAR file or a set of class files, you must first ensure that all of the classes that the scanned classes depend upon are present in the class path. set the class path using the --class-path option described in Options for the jdeprscan Command. typically, you would use the same class path as the one that you use when invoking your application. same energy, same path β¨
if the jdeprscan can't find all the dependent classes, it will generate an error message for each class that's missing. these error messages are typically of the form:
error: cannot find class ...
if these errors occur, then you must adjust the class path so that it includes all dependent classes. not me having to fix my classpath again π β but like, do it, it's important.
π¦ OPTIONS FOR THE JDEPRSCAN COMMAND π¦
the following options are available, and yes, I'm listing every single one because we don't skip π
--class-pathpath β provides a search path for resolution of dependent classes. path can be a search path that consists of one or more directories separated by the system-specific path separator. for example:- Linux and OS X:
--class-path /some/directory:/another/different/dir
Note: on Windows, use a semicolon (;) as the separator instead of a colon (:). πͺ
- Windows:
--class-path \some\directory;\another\different\dir
--for-removalβ limits scanning or listing to APIs that are deprecated for removal. can't be used with a release value of 6, 7, or 8. like, it just can't, okay? π«--full-versionβ prints out the full version string of the tool. the whole thing, no edits π₯--helpor-hβ prints out a full help message. we love a helpful icon π--listor-lβ prints the set of deprecated APIs. no scanning is done, so no directory, jar, or class arguments should be provided. just vibes, no args π--release 6|7|8|9β specifies the Java SE release that provides the set of deprecated APIs for scanning.--verboseor-vβ enables additional message output during processing. she's chatty, we love her π£οΈ--versionβ prints out the abbreviated version string of the tool. short and slay β¨
π₯ EXAMPLE OF JDEPRSCAN OUTPUT π₯
the JAR file for this library will be named something similar to commons-math3-3.6.1.jar. to scan this JAR file for the use of deprecated APIs, run the following command:
jdeprscan commons-math3-3.6.1.jar
this command produces several lines of output. for example, one line of output might be:
class org/apache/commons/math3/util/MathUtils uses deprecated method java/lang/Double::<init>(D)V
Note: the class name is specified using the slash-separated binary name as described in JVMS 4.2.1. this is the form used internally in class files. π§¬
the deprecated API it uses is a method on the java.lang.Double class.
the name of the deprecated method is <init>, which is a special name that means that the method is actually a constructor. another special name is <clinit>, which indicates a class static initializer. main character names only π«
other methods are listed just by their method name. following the method name is the argument list and return type:
(D)V
this indicates that it takes just one double value (a primitive) and returns void. the argument and return types can become cryptic. for example, another line of output might be:
class org/apache/commons/math3/util/Precision uses deprecated method java/math/BigDecimal::setScale(II)Ljava/math/BigDecimal;
in this line of output, the deprecated method is on class java.math.BigDecimal, and the method is setScale(). in this case, the (II) means that it takes two int arguments. the Ljava/math/BigDecimal; after the parentheses means that it returns a reference to java.math.BigDecimal. it's giving cryptic but make it fashion π
β JDEPRSCAN ANALYSIS CAN BE VERSION-SPECIFIC β
you can use jdeprscan relative to the previous three JDK releases. for example, if you are running JDK 9, then you can check against JDK 8, 7, and 6. time travel, but make it Java π°οΈ
as an example, look at this code snippet:
public class Deprecations {
SecurityManager sm = new RMISecurityManager(); // deprecated in 8
Boolean b2 = new Boolean(true); // deprecated in 9
}
the complete class compiles without warnings in JDK 7. love that for her π«Ά
if you run jdeprscan on a system with JDK 9, then you see:
$ jdeprscan --class-path classes --release 7 example.Deprecations
(no output)
run jdeprscan with a release value of 8:
$ jdeprscan --class-path classes --release 8 example.Deprecations
class example/Deprecations uses type java/rmi/RMISecurityManager deprecated
class example/Deprecations uses method in type java/rmi/RMISecurityManager deprecated
run jdeprscan on JDK 9:
$ jdeprscan --class-path classes example.Deprecations
class example/Deprecations uses type java/rmi/RMISecurityManager deprecated
class example/Deprecations uses method in type java/rmi/RMISecurityManager deprecated
class example/Deprecations uses method java/lang/Boolean <init> (Z)V deprecated
look at all those deprecations showing up. she ate πβ¨
that's the whole page, bestie. this is JDK 17, dated 2021, and it's jdeprscan(1) signing off π go scan something and slay π
π¦ where this page comes from
- opensuse-leap 16.0: java-17-openj9-devel 17.0.19.0-bp160.1.1 Β· Apache-1.1 AND Apache-2.0 AND EPL-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND LicenseRef-SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-17-openj9-devel 17.0.19.0-bp160.1.1 Β· Apache-1.1 AND Apache-2.0 AND EPL-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND LicenseRef-SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-17-openj9-devel 17.0.19.0-bp160.1.1 Β· Apache-1.1 AND Apache-2.0 AND EPL-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND LicenseRef-SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-17-openj9-devel 17.0.19.0-bp160.1.1 Β· Apache-1.1 AND Apache-2.0 AND EPL-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND LicenseRef-SUSE-Public-Domain AND W3C
- Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms