자바 9(Java 9)에는 코드 마이그레이션과 유지보수를 돕는 다양한 진단 도구가 포함되어 있으며, 그중 Jdeps와 Jdeprscan이 가장 널리 활용됩니다. 두 도구는 이름이 비슷하고 JDK와 함께 배포되지만, 목적과 기능은 완전히 다릅니다.
Jdeps는 클래스와 패키지 수준의 의존성(dependency)을 분석하는 도구입니다. 예를 들어 "jdeps -jdkinternals jararchive.jar" 명령을 실행하면 자바 내부 API(JDK Internal API)를 사용 중인 모든 클래스의 목록이 출력되며, 의존성에 대한 상세한 설명을 제공합니다. 반면 Jdeprscan은 지정된 JAR 아카이브가 사용하는 사용 중단(deprecated) API를 찾아내는 스캐너로, 특히 "--for-removal" 옵션과 함께 사용하면 향후 삭제될 예정인 API의 사용 여부를 손쉽게 확인할 수 있습니다. 단, Jdeprscan은 JDK 메서드의 사용 중단 여부만 표시할 수 있으며, 서드파티(third-party) JAR 내부의 사용 중단 항목까지 확인하는 용도로는 사용할 수 없습니다.
| 구분 | Jdeps | Jdeprscan |
|---|---|---|
| 주요 목적 | 클래스·패키지·모듈 간 의존성 분석 | 사용 중단(deprecated) API 사용 여부 검사 |
| 분석 대상 | .class 파일, 디렉터리, JAR 파일, 모듈 | .class 파일, 디렉터리, JAR 파일 |
| 대표 옵션 | -jdkinternals, --list-deps, -verbose 등 | --for-removal, --release, --list 등 |
| 활용 시나리오 | 모듈화 준비, JDK 내부 API 사용 탐지 | JDK 업그레이드 전 deprecated API 점검 |
Jdeps 도구란?
- "jdeps"는 패키지 수준과 클래스 수준의 의존성을 모두 분석할 수 있는 클래스 의존성 분석기(class dependency analyzer)입니다.
- "jdeps class_file" — 지정한 클래스 파일의 패키지 수준 의존성을 출력합니다.
- "jdeps -verbose" — 클래스 수준의 의존성을 상세하게 출력합니다.
- "jdeps jar_file" — 지정한 JAR 파일의 패키지 수준 의존성을 출력합니다.
- "jdeps --inverse --require module_name" — 지정한 자바 모듈의 패키지 수준 역방향(reverse) 의존성을 출력합니다.
아래 "jdeps --help" 명령 실행 결과에서 전체 옵션 목록을 확인할 수 있습니다.
C:\Users\user>jdeps --help
Usage: jdeps <options> <path ...>
<path> can be a pathname to a .class file, a directory, a JAR file.
Possible options include:
-dotoutput <dir>
--dot-output <dir> Destination directory for DOT file output
-s -summary Print dependency summary only.
-v -verbose Print all class level dependences
Equivalent to -verbose:class -filter:none.
-verbose:package Print package-level dependences excluding
dependences within the same package by default
-verbose:class Print class-level dependences excluding
dependences within the same package by default
-apionly
--api-only Restrict analysis to APIs i.e. dependences
from the signature of public and protected
members of public classes including field
type, method parameter types, returned type,
checked exception types etc.
-jdkinternals
--jdk-internals Finds class-level dependences on JDK internal
APIs. By default, it analyzes all classes
on --class-path and input files unless -include
option is specified. This option cannot be
used with -p, -e and -s options.
WARNING: JDK internal APIs are inaccessible.
--check <module-name>[,<module-name>...]
Analyze the dependence of the specified modules
It prints the module descriptor, the resulting
module dependences after analysis and the
graph after transition reduction. It also
identifies any unused qualified exports.
--generate-module-info <dir>
Generate module-info.java under the specified
directory. The specified JAR files will be
analyzed. This option cannot be used with
--dot-output or --class-path. Use
--generate-open-module option for open modules.
--generate-open-module <dir>
Generate module-info.java for the specified
JAR files under the specified directory as
open modules. This option cannot be used with
--dot-output or --class-path.
--list-deps Lists the dependences and use of JDK internal APIs.
--list-reduced-deps Same as --list-deps with not listing
the implied reads edges from the module graph
If module M1 depends on M2 and M3,
M2 requires public on M3, then M1 reading M3 is
implied and removed from the module graph.
-cp <path>
-classpath <path>
--class-path <path> Specify where to find class files
--module-path <module path>
Specify module path
--upgrade-module-path <module path>
Specify upgrade module path
--system <java-home> Specify an alternate system module path
--add-modules <module-name>[,<module-name>...]
Adds modules to the root set for analysis
-m <module-name>
--module <module-name> Specify the root module for analysis
--multi-release <version>
Specifies the version when processing
multi-release jar files. should
be integer >= 9 or base.
Options to filter dependences:
-p <pkg>
-package <pkg>
--package <pkg> Finds dependences matching the given package
name (may be given multiple times).
-e <regex>
-regex <regex>
--regex <regex> Finds dependences matching the given pattern.
--require <module-name> Finds dependences matching the given module
name (may be given multiple times). --package,
--regex, --require are mutual exclusive.
-f <regex> -filter <regex> Filter dependences matching the given
pattern. If given multiple times, the last
one will be used.
-filter:package Filter dependences within the same package.
This is the default.
-filter:archive Filter dependences within the same archive.
-filter:module Filter dependences within the same module.
-filter:none No -filter:package and -filter:archive
filtering. Filtering specified via the
-filter option still applies.
Options to filter classes to be analyzed:
-include <regex> Restrict analysis to classes matching pattern
This option filters the list of classes to
be analyzed. It can be used together with
-p and -e which apply pattern to the dependences
-P -profile Show profile containing a package
-R -recursive Recursively traverse all run-time dependences.
The -R option implies -filter:none. If -p,
-e, -f option is specified, only the matching
dependences are analyzed.
-I --inverse Analyzes the dependences per other given options
and then find all artifacts that directly
and indirectly depend on the matching nodes.
This is equivalent to the inverse of
compile-time view analysis and print
dependency summary. This option must use
with --require, --package or --regex option.
--compile-time Compile-time view of transitive dependences
i.e. compile-time view of -R option.
Analyzes the dependences per other given options
If a dependence is found from a directory,
a JAR file or a module, all classes in that
containing archive are analyzed.
-q -quiet Do not show missing dependences from
--generate-module-info output.
-version --version Version informationJdeprscan 도구란?
- "jdeprscan"은 사용 중단된 API 요소를 검색하는 자바 Deprecated API 스캐너 도구입니다.
- "jdeprscan class_file" — 지정한 자바 클래스 파일에서 사용 중단된 API를 검색합니다.
- "jdeprscan jar_file" — 지정한 JAR 파일에서 사용 중단된 API를 검색합니다.
- "jdeprscan --release X" — 특정 JDK 릴리스에서 사용 중단된 API를 기준으로 검색합니다.
- "jdeprscan --list --release X" — 특정 JDK 릴리스의 사용 중단된 API 전체 목록을 출력합니다.
아래 "jdeprscan --help" 명령 실행 결과에서 전체 옵션 목록을 확인할 수 있습니다.
C:\Users\User>jdeprscan --help
Usage: jdeprscan [options] {dir|jar|class} ...
options:
--class-path PATH
--for-removal
--full-version
-h --help
-l --list
--release 6|7|8|9
-v --verbose
--version
Scans each argument for usages of deprecated APIs. An argument may be a
directory specifying the root of a package hierarchy, a JAR file, a class
file, or a class name. The class name must be specified using a fully
qualified class name using the $ separator character for nested classes,
for example, java.lang.Thread$State
The --class-path option provides a search path for resolution of dependent
classes.
The --for-removal option limits scanning or listing to APIs that are
deprecated for removal. Cannot be used with a release value of 6, 7, or 8.
The --full-version option prints out the full version string of the tool.
The --help option prints out a full help message.
The --list (-l) option prints out the set of deprecated APIs. No scanning
is done, so no directory, jar, or class arguments should be provided.
The --release option specifies the Java SE release that provides the set
of deprecated APIs for scanning.
The --verbose (-v) option enables additional message output during
processing.
The --version option prints out the abbreviated version string of the tool.마무리
정리하면, Jdeps는 "코드가 무엇에 의존하는가"를 파악하는 의존성 분석 도구이고, Jdeprscan은 "더 이상 권장되지 않는 API를 사용하고 있는가"를 점검하는 도구입니다. JDK 버전을 업그레이드하거나 모듈 시스템으로 전환하기 전에 두 도구를 함께 활용하면 잠재적인 호환성 문제를 사전에 발견하고 더욱 안정적으로 마이그레이션을 진행할 수 있습니다.