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 分