npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

java-class-analyzer-cli

v1.0.1

Published

Project-scoped Java dependency class analyzer CLI

Readme

java-class-analyzer-cli

English | 简体中文

本项目源自 handsomestWei/java-class-analyzer-mcp-server,是其 CLI 版本,感谢原作者的开源贡献。

java-class-analyzer-cli 是一个项目级 Java 依赖类分析工具。它的目标是像 maven-indexer-cli 一样安装后即可在命令行使用,不需要额外配置 MCP,同时更适合项目组在具体 Java 项目里分析依赖类、方法签名和反编译源码。

安装

npm install -g java-class-analyzer-cli

从源码安装:

npm install
npm run build
npm link

常用命令

java-class-analyzer-cli scan --project .
java-class-analyzer-cli search-classes --project . Foo
java-class-analyzer-cli get-class --project . com.foo.Bar --type source
java-class-analyzer-cli get-class --project . com.foo.Bar --type signatures
java-class-analyzer-cli analyze-class --project . com.foo.Bar --json

工作原理

scan 会在目标项目目录中执行 Maven 命令,获取项目最终解析出的 classpath:

mvn -q dependency:build-classpath -Dmdep.outputFile=.java-class-analyzer/classpath.txt

随后它只扫描该 classpath 中列出的 jar,并写入项目级索引:

.java-class-analyzer/class-index.json

索引条目包含:

  • 类全名
  • jar 路径
  • 尽量推断出的 Maven 坐标
  • classpath 顺序
  • jar 的 mtime 和 size

如果多个 classpath jar 中包含同一个类,默认选择 classpath 顺序最靠前的 jar,并在命令输出中提示冲突。

对于 Maven 多模块项目,CLI 会基于 reactor 解析 classpath。如果模块 A 依赖兄弟模块 B,且 B 尚未 install 到本地 Maven 仓库,CLI 会先构建所需 reactor artifact,并把这些内部模块 jar 从依赖索引中排除。

执行 get-class --type source 时,CLI 会先在选中的 classpath jar 同目录下查找同版本 *-sources.jar。如果其中存在匹配的 .java.kt 源文件,就直接返回源码;只有找不到匹配源码时才启动 CFR 反编译。

缓存目录

.java-class-analyzer/
  classpath.txt
  class-index.json

项目目录下只保存轻量的 classpath 和类索引。默认情况下,get-class --type source 只把反编译源码输出到命令行,不会持久保存,因此不会让业务项目目录或用户缓存目录堆满依赖源码。

如果希望复用反编译结果,可以显式添加 --cache-source,此时源码会写入用户级缓存目录,例如 Windows 下的 %LOCALAPPDATA%\java-class-analyzer-cli\...。可以通过 JAVA_CLASS_ANALYZER_CACHE_DIR 覆盖缓存位置。缓存会绑定 jar 指纹,而不是只按 className 缓存,因此项目升级依赖后不会读到旧版本 jar 的反编译结果。

CFR

CLI 会按以下顺序查找 CFR:

  1. --cfr-path
  2. CFR_PATH
  3. lib/cfr-0.152.jar

打包前可以把 cfr-0.152.jar 放到 lib/ 目录下;也可以通过 CFR_PATH 指向已有的 CFR jar。

当前包内置了 MIT 许可证下的 CFR 0.152,详见 THIRD_PARTY_NOTICES.md

Maven 选项

可能触发扫描的命令支持这些选项:

--settings path/to/settings.xml
--scope compile
--maven-args -DskipTests -Pdev
--auto-scan

search-classesget-classanalyze-class 默认不会静默自动扫描。如果索引不存在,请先执行 scan,或显式添加 --auto-scan

和 maven-indexer-cli 的区别

maven-indexer-cli 面向全局 Maven/Gradle 仓库索引,适合回答“这台机器上有哪些依赖类?”。

java-class-analyzer-cli 面向当前项目最终解析出的 classpath,适合回答“这个项目实际使用的是哪个依赖类、哪个版本?”。