JavaLens
io.github.pzalutski-pixel由 GitHub 账号 pzalutski-pixel 发布v1.5.3更新于 Oct 24, 2026
75 semantic Java analysis tools via Eclipse JDT: navigation, refactoring, code intelligence.
概览
JavaLens 基于 Eclipse JDT 为 AI 助手提供 75 个编译器级 Java 分析工具,涵盖导航、引用查找、重构编辑与代码度量。
- 可以做什么
- 搜索与导航符号:通配符符号搜索、跳转定义、引用、实现、类型层级、文件内符号,以及指定位置的符号、类型、方法、字段信息
- 查找细粒度引用:注解、实例化、强制转换、instanceof 判断、throws 与 catch、方法引用、类型参数、反射调用
- 分析代码:诊断、语法校验、调用层级、字段写入、测试、未使用与不可达代码、受影响的测试、潜在缺陷、Javadoc、数据流与控制流、Spring 依赖注入、JPA 模型与 HTTP 端点
- 执行组合查询,一次调用汇总导入、类型、诊断、成员、层级与用法
- 生成重构文本编辑(重命名、提取、内联、修改签名、上移下移等),但不直接写入文件
- 输出度量与结构:复杂度、依赖图、循环依赖、过大类、命名违规、项目结构与类路径
- 适用场景
- 适用于助手处理 Java 代码库、而文本搜索不够精确的场景,例如重载方法、继承、泛型或需要安全重构时。适合在改动前确认真实用法、判断改动影响哪些测试,或审查架构与复杂度。
- 运行要求
- 以 stdio 在本地运行。需要 Java 21 或更高版本位于 PATH 或通过 JAVA_HOME 指定;使用 npm 方式(npx javalens-mcp)还需 Node.js 18+。需通过 -data 参数指定工作区目录。可选环境变量包括 JAVA_PROJECT_PATH(启动时自动加载项目)、JAVALENS_TIMEOUT_SECONDS、JAVALENS_DISK_SYNC、JAVALENS_LOG_LEVEL 以及 JVM 与构建工具参数。
安装
在 SourceWeft 中
- 打开 控制台中的 JavaLens,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
JavaLens: AI-First Code Analysis for Java
[GitHub release] [License: MIT] [Java 21]
An MCP server providing 75 semantic analysis tools for Java, built directly on Eclipse JDT for compiler-accurate code understanding.
Built for AI Agents
JavaLens exists because AI systems need compiler-accurate insights that reading source files cannot provide. When an AI uses grep or Read to find usages of a method, it cannot distinguish:
- A method call from a method with the same name in an unrelated class
- A field read from a field write
- An interface implementation from an unrelated class
- A cast to a type from other references to that type
This leads to incorrect refactorings, missed usages, and incomplete understanding of code behavior.
Compiler-Accurate Analysis
JavaLens provides compiler-accurate code analysis through Eclipse JDT—the same engine that powers Eclipse IDE. Unlike text search, JDT understands:
- Type resolution across inheritance hierarchies
- Method overloading and overriding
- Generic type arguments
- Import resolution and classpath dependencies
- Java source from version 1.1 through Java 25 (markdown Javadoc, module imports, compact source files, flexible constructor bodies)
- Lombok-generated members — a bundled agent makes
@Dataaccessors and the like resolve, so code using them is not flagged as undefined
Example: Finding all places where UserService.save() is called:
AI Training Bias Warning
⚠️ Important for AI developers and users
AI models may exhibit trained bias toward native tools (Grep, Read, LSP) over MCP server tools, even when semantic analysis provides better results. This happens because:
- Training data contains extensive grep/text-search patterns
- Native tools are "always available" in the model's experience
- The model may not recognize when semantic analysis is superior
To get the best results:
Add guidance to your project instructions or system prompt (e.g., CLAUDE.md for Claude Code):
What is JavaLens?
JavaLens is an MCP server that gives AI assistants deep understanding of Java codebases. It provides semantic analysis, navigation, refactoring, and code intelligence tools that go beyond simple text search.
Why Not LSP?
Language Server Protocol was designed for IDE autocomplete and basic navigation—not for AI agent workflows that require deep semantic analysis.
JavaLens wraps Eclipse JDT Core directly via OSGi, providing:
- Fine-grained reference types: Find specifically casts, annotations, throws clauses, catch blocks, instanceof checks, method references, type arguments
- Read vs write access distinction: Track where fields are mutated vs just read
- Indexed search: JDT pre-builds an index at load time, so symbol/reference queries do not walk source files
- Full AST access: Direct manipulation for complex refactorings
Installation
Prerequisites
- Java 21 or later (must be on PATH or set
JAVA_HOME) — required for both install paths. - Node.js 18+ — required only if you use the npm/
npxinstall path below. Skip if you use the direct-download path.
JavaLens is an analytical server, not a compiler. It uses Eclipse JDT 2025-12 to parse and understand Java source code from version 1.1 through 25. Java 21 is required only as the server runtime.
Install from GitHub Releases (recommended — Java only)
This is the simplest path if you already have Java 21 and don't have Node.js. Download from Releases:
Extract to a location of your choice (e.g., /opt/javalens or C:\javalens). Then point your MCP client at the bundled jar — see Configure MCP Client below.
Install via npm (requires Node.js 18+)
If you already have Node.js, npx will download and cache the JavaLens distribution (~23 MB) on first run:
Configure MCP Client
Add to your MCP configuration (e.g., .mcp.json for Claude Code):
The -data argument specifies where JavaLens stores its workspace metadata. See How Workspaces Work below.
Auto-Load a Project
Set JAVA_PROJECT_PATH to auto-load a project when the server starts:
Note: Project loading happens asynchronously in the background. The MCP server responds immediately while the project loads. Use
health_checkto monitor loading status—it will show"project.status": "loading"until complete, then"loaded"when ready.
How Workspaces Work
Unlike in-memory code models, Eclipse JDT requires a workspace directory to store:
- Search indexes for fast symbol lookup
- Compilation state and caches
- Project metadata
Workspaces Are Outside Your Source
JavaLens creates its workspace outside your source project to keep your codebase clean:
Why this matters:
- No pollution: Your source tree stays clean—no
.projector.classpathfiles - No conflicts: Works alongside any build system without interference
- Session isolation: Each MCP session gets its own workspace, enabling concurrent analysis
Session Lifecycle
- JavaLens starts and creates a unique workspace:
{base}/{uuid}/ load_projectcreates linked folders pointing to your source- JDT builds indexes in the workspace (not in your project)
- When the session ends, the workspace is cleaned up
Tools
Navigation (10 tools)
Fine-Grained Reference Search (9 tools)
These use JDT's unique reference type constants—not available through LSP:
Analysis (20 tools)
Compound Analysis (4 tools)
Combine multiple queries to reduce round-trips:
Refactoring (16 tools)
All refactoring tools return text edits (and new-file content where a refactoring creates one) rather than applying changes directly:
Quick Fixes (5 tools)
Metrics (5 tools)
Project & Infrastructure (6 tools)
Usage
Basic Workflow
Coordinate System
All line/column parameters are zero-based:
- Line 0, Column 0 = first character of file
Path Handling
- Response paths are relative by default
- All paths use forward slashes for cross-platform consistency
- Input paths can be relative or absolute
Important Notes
Disk Synchronization
Every answer is verified against the files on disk at query time. Before any tool logic runs, JavaLens content-hashes the known source files, detects edits, additions, and deletions (the agent reports nothing — the server discovers changes itself), repairs exactly what changed, waits for the search index to absorb the repair, and only then answers. There is no file watcher and no background thread — verification is synchronous inside the query the agent issued, so there are no race conditions.
The agent's loop is just: edit → query.
load_project is needed only on first use, when a response reports RELOAD_REQUIRED (a build file like pom.xml changed, so the classpath must be rebuilt), or to rebuild everything from scratch. If verification itself fails, the query returns VERIFICATION_FAILED rather than an unverified answer.
Cost: verification is hash-based and parallel — measured per query at ~2 ms for a 72-file project, ~25 ms at 1,000 files, ~180 ms at 10,000 files. Repairs cost only what changed (one edited file reconciles in well under a second), never a full reindex.
Manual mode: set JAVALENS_DISK_SYNC=manual to restore the pre-1.5.0 contract — answers reflect the last load and the agent calls load_project after editing files. Tool descriptions and the MCP instructions field always state the active contract, and health_check reports it as diskSync.
Refactoring Returns Edits
Refactoring tools return text edits but don't modify files. This gives visibility into what would change before applying.
Session Isolation
Each MCP session is independent with its own workspace UUID. Multiple sessions can analyze the same project concurrently.
Build System Support
JavaLens loads three real build systems plus plain Java directories. Each is exercised end-to-end in CI against synthetic real-shaped fixtures (multi-module reactors with cross-module deps, real external libraries, annotation processors).
JavaLens asks the build tool itself during the load and takes the model from its answer, writing nothing into the project tree:
- Maven: one run (
--fail-at-end) ofhelp:effective-pomanddependency:build-classpath. A module Maven cannot resolve (one that depends on a module of the same build that is not installed, typically) is named by aBUILD_TOOL_FAILED; the rest of the model is still Maven's. Modules declared only in an inactive profile, and Gradle projects of asettings.gradlebeside the root pom, stay linked withINCLUDED_OUTSIDE_BUILD. - Gradle: one run with an init script that reports projects, custom
projectDirs, included builds, source sets, generated-source directories, classpath and per-project levels. - Bazel:
bazel queryfor the Java targets and sources and the build files,bazel aqueryfor each javac action,bazel info execution_root, all with--lockfile_mode=off.
When the tool cannot run or reports no model, JavaLens reads the build files itself as code (comments and strings declare nothing: poms as XML, Gradle settings and Bazel BUILD files through a lexer), lays modules out by convention where the files say nothing, and reports buildModel.source = static-read with a BUILD_MODEL_STATIC warning naming what such a read cannot see.
A change to any file the build reads, including one created after the load (gradle.properties, a version catalog, buildSrc, .mvn/maven.config, .bazelrc, a .bzl file, the pom of a module outside the root), makes the next query report RELOAD_REQUIRED naming it.
load_project and health_check both report a buildModel summary (build system, where the structure came from: build-tool, static-read or convention, analysis level, modules) and every load warning, so a degraded load is visible wherever the agent looks, including projects auto-loaded through JAVA_PROJECT_PATH. Warning codes:
Configuration
Building from Source
Distributions are output to org.javalens.product/target/products/.
Build Requirements
- Java 21+ (server runtime)
- Maven 3.9+ (wrapper included as
./mvnw)
To run the full test suite (which includes end-to-end tests against real Maven, Gradle, and Bazel builds), the corresponding tools must also be on PATH:
- Maven (provided by the wrapper)
- Gradle 8+
- Bazel 9+ (or
bazelisk)
Tests gracefully skip when a tool is missing on a developer machine. Set JAVALENS_TESTS_REQUIRE_TOOLS=true to flip the gate: missing tools cause a hard failure instead of a skip. CI runs with this flag set so any provisioning gap surfaces as a real failure rather than weakening the suite silently.
Testing
Build-system coverage is structured as focused per-bug tests plus realistic end-to-end tests. The end-to-end tests load a single representative project per build system that exercises every fix in one pass — multi-module Maven with Lombok APT and cross-module references; multi-project Gradle with annotation processors; multi-target Bazel with cross-target deps. CI runs them on Linux and macOS; Windows line endings are covered by tests that write CRLF files explicitly.
Architecture
License
MIT License - see LICENSE for details.
来源:README.md,提交 aa55d29
工具
0版本历史
2- v1.5.3最新Oct 18, 2026
- v1.5.1Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分