Java Class Analyzer
Provides Java class analysis capabilities for AI Agents, supporting Maven dependency scanning and class file decompilation to retrieve source code.
Dependency Installation
Install dependencies before first use:
pip install -r scripts/requirements.txtCore Features
1. Scan Maven Dependencies
Scan the project's Maven dependency tree, extract all JAR files, and build a class index:
python scripts/scan_dependencies.py <project_path> [--force-refresh]Parameters:
project_path: Root directory of the Maven project (absolute path)--force-refresh: Force refresh, ignore cache
Output: Generates class index file to ~/analyser-mcp/{project_name}/class_index.json
2. Decompile Java Class
Decompile and retrieve source code by fully qualified class name:
python scripts/decompile_class.py <class_name> <project_path> [--no-cache]Parameters:
class_name: Fully qualified class name, e.g.,com.alibaba.fastjson2.JSONproject_path: Root directory of the Maven project--no-cache: Do not use cache
Output: Prints the decompiled Java source code
3. Search Class Name
Search for class names in the established index:
python scripts/search_class.py <keyword> <project_path>Parameters:
keyword: Search keyword (supports partial matching)project_path: Root directory of the Maven project
Usage Workflow
- First Use: Run
scan_dependencies.pyto build the class index - Search Class: Use
search_class.pyto find the target class - View Source: Use
decompile_class.pyto decompile the specified class
Typical Scenarios
Scenario 1: View Third-Party Library Implementation
# 1. Build index (only needed for first time)
python scripts/scan_dependencies.py /path/to/my-project
# 2. Search class
python scripts/search_class.py JSON /path/to/my-project
# 3. Decompile to view source code
python scripts/decompile_class.py com.alibaba.fastjson2.JSON /path/to/my-projectScenario 2: Troubleshoot Dependency Conflicts
Build the index first, then search for classes with the same name to see which JAR files they come from.
Detailed Documentation
See reference.md for index file format, caching mechanism, and advanced configuration.