jdeprscan tool can be used as a static analyzing tool which scans the Class / JAR file for the usage of deprecated API. jdeprscan tool identifies the deprecated APIs which defined by Java SE Deprecated APIs, third-party libraries will not be identified.
Syntax for jdeprscan
jdeprscan [ options ] {dir|jar|class}
Options for jdeprscan
—class-path PATH – Search Path for the classes to be searched
–full-version – Prints the version of the jdeprscan tool
— release 6|7|8|9 – Uses the specified Java version and lists out the deprecated API
–list (or) –l – Prints the list of all deprecated API ( We should not provide any dir or jar or class as no scanning is done)
–help (or) -h – Displays the help message
–for-removal – Limits scanning or listing to APIs that are deprecated for removal.
–verbose (or) -v – Enables additional message output during processing
Arguments for jdeprscan
- dir: Directory
- jar: JAR file
- class: Class name or class file
jdeprscan Tool Example
Let’s try scan the below class and find out how the jdeprscan works
public class DeprecationTest { public static void main(String[] args) { Integer i = new Integer(1); System.out.println(i); } }
output:
c:\JIP>jdeprscan "DeprecationTest.class" class DeprecationTest uses deprecated method java/lang/Integer::(I)V
Version specific jdeprscan
jdeprscan can also scan the code based on the previous JDK releases (JDK 8, 7, and 6), let’s say you are currently running with JDK 9 and you want to validate your code with JDK 8, it is also possible in jdeprscan using the –release option
Java 7 c:\JIP>jdeprscan --release 7 "C:\jdk1.5.0_08\lib\htmlconverter.jar" warning: unknown enum constant javax.jws.WebParam.Mode.IN warning: unknown enum constant javax.jws.soap.SOAPBinding.Use.LITERAL warning: unknown enum constant javax.annotation.Resource.AuthenticationType.CONTAINER Jar file C:\jdk1.5.0_08\lib\htmlconverter.jar: class sun/plugin/converter/gui/ConverterGUI uses deprecated method java/awt/Dialog::show()V Java 8 c:\JIP>jdeprscan --release 8 "C:\jdk1.5.0_08\lib\htmlconverter.jar" warning: unknown enum constant javax.jws.WebParam.Mode.IN warning: unknown enum constant javax.jws.soap.SOAPBinding.Use.LITERAL warning: unknown enum constant javax.annotation.Resource.AuthenticationType.CONTAINER Jar file C:\jdk1.5.0_08\lib\htmlconverter.jar: class sun/plugin/converter/gui/ConverterGUI uses deprecated method java/awt/Dialog::show()V Java 9 c:\JIP>jdeprscan --release 9 "C:\jdk1.5.0_08\lib\htmlconverter.jar" Jar file C:\jdk1.5.0_08\lib\htmlconverter.jar: class sun/plugin/converter/engine/PluginConverter uses deprecated method java/lang/Integer::(Ljava/lang/String;)V class sun/plugin/converter/gui/ConverterGUI uses deprecated method java/awt/Dialog::show()V class sun/plugin/converter/resources/Converter uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_de uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_es uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_fr uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_it uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_ja uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_ko uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_sv uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_zh_CN uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_zh_HK uses deprecated method java/lang/Integer::(I)V class sun/plugin/converter/resources/Converter_zh_TW uses deprecated method java/lang/Integer::(I)V
Leave a Reply