Computer >> 컴퓨터 >  >> 프로그래밍 >> Java

Java 9에서 jdeps 도구가 중요한 이유

jdepsJava 클래스 의존성 분석 도구(Java Class Dependency Analyzer)로, 주어진 Java 클래스 파일의 패키지 수준 또는 클래스 수준 의존성을 보여주는 명령줄 도구입니다. 분석할 입력 클래스는 .class 파일 경로, 디렉터리, JAR 파일 또는 완전한 클래스 이름(fully qualified class name)으로 지정할 수 있습니다.

"jdeps"는 JDK 8부터 JDK 설치에 포함되어 있으며, "%JAVA_HOME%\bin\jdeps.exe" 프로그램 파일로 제공됩니다. 만약 "%JAVA_HOME%\bin" 디렉터리가 "PATH" 환경 변수에 포함되어 있다면, "jdeps --help" 명령을 실행하여 모든 옵션의 전체 목록을 확인할 수 있습니다.

jdeps --help 명령으로 확인할 수 있는 옵션 목록

C:\Program Files\Java\jdk-9.0.4>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 information

Java 9에서 jdeps가 중요한 이유

Java 9에서는 모듈 시스템(Project Jigsaw)이 도입되면서 jdeps의 역할이 더욱 중요해졌습니다. 특히 다음과 같은 이유로 개발자에게 필수적인 도구입니다.

  • JDK 내부 API 사용 탐지: Java 9부터는 JDK 내부 API(com.sun.* 등)에 대한 접근이 제한되었습니다. jdeps의 --jdk-internals 옵션을 사용하면 코드가 사용 중인 내부 API를 미리 파악하여 마이그레이션 전에 문제를 해결할 수 있습니다.
  • 모듈화 준비 지원: --generate-module-info 옵션은 기존 JAR 파일에 대한 module-info.java 파일을 자동 생성해 주어, 기존 라이브러리를 Java 9 모듈 시스템으로 전환하는 작업을 크게 단순화합니다.
  • 의존성 정리: 패키지 및 클래스 수준의 의존성을 상세히 분석하여 불필요한 의존성을 찾아내고 애플리케이션 구조를 개선할 수 있습니다.

결론적으로 jdeps는 Java 9의 모듈 시스템으로 원활하게 전환하기 위한 핵심 진단 도구이며, 기존 애플리케이션의 호환성 검사와 모듈화 작업에 없어서는 안 될 유틸리티입니다.