java-classpath-search
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJava Classpath Search
Java类路径搜索
Fast search across all Maven dependencies to find which JARs contain a Java class.
可在所有Maven依赖中快速搜索,查找哪些JAR包含指定的Java类。
Overview
概述
This skill searches a pre-built index of all classes in your Maven local repository, providing instant results for classpath queries. It's essential for resolving imports, debugging classpath conflicts, and discovering dependency sources.
本技能会搜索Maven本地仓库中所有类的预构建索引,可即时返回类路径查询结果,是解决import问题、调试类路径冲突、查找依赖来源的必备工具。
When to Use
适用场景
- Finding which dependency provides a class
- Resolving "class not found" errors
- Checking for version conflicts (multiple JARs with same class)
- Discovering available implementations of an interface
- Understanding your project's dependency tree
- Verifying a dependency is in your local Maven repo
- 查找哪个依赖提供了指定类
- 解决「类未找到」错误
- 检查版本冲突(多个JAR存在同名类)
- 查找某个接口的可用实现
- 梳理项目的依赖树
- 验证某个依赖是否存在于本地Maven仓库中
Quick Reference
快速参考
Search patterns:
- Fully qualified:
com.fasterxml.jackson.databind.ObjectMapper - Simple name:
ObjectMapper - Partial pattern:
jackson.ObjectMapper
Index location:
$HOME/.cache/quarkusdev-skills/class-index.txtIndex refresh: Automatic if missing or older than 7 days
搜索模式:
- 全限定名:
com.fasterxml.jackson.databind.ObjectMapper - 简单名称:
ObjectMapper - 部分匹配模式:
jackson.ObjectMapper
索引位置:
$HOME/.cache/quarkusdev-skills/class-index.txt索引刷新: 若索引缺失或超过7天未更新则自动刷新
Implementation
实现逻辑
Step 1: Determine Search Pattern
步骤1:确定搜索模式
Parse the user input (available as ):
$ARGUMENTS| Input | Pattern Conversion |
|---|---|
| |
| |
| |
解析用户输入(存储在中):
$ARGUMENTS| 输入 | 模式转换 |
|---|---|
| |
| |
| |
Step 2: Ensure Index is Available
步骤2:确保索引可用
The class index is a tab-separated file mapping class paths to JAR paths.
bash
INDEX="$HOME/.cache/quarkusdev-skills/class-index.txt"类索引是一个制表符分隔的文件,存储了类路径到JAR路径的映射关系。
bash
INDEX="$HOME/.cache/quarkusdev-skills/class-index.txt"Check if index needs rebuilding (missing or older than 7 days)
检查是否需要重建索引(缺失或超过7天未更新)
if [ ! -f "$INDEX" ] || [ $(find "$INDEX" -mtime +7 2>/dev/null | wc -l) -gt 0 ]; then
Dispatch index rebuild as subagent (can take 30-60 seconds)
Use Agent tool with prompt:
"Run the build-class-index.sh script from this skill directory
Report when indexing is complete."
Wait for subagent to complete before continuing
fi
**Note:** Index building is dispatched to a subagent to keep the main conversation responsive. The script uses 8 parallel workers and typically completes in under 60 seconds.if [ ! -f "$INDEX" ] || [ $(find "$INDEX" -mtime +7 2>/dev/null | wc -l) -gt 0 ]; then
将索引重建任务派发给子Agent(可能需要30-60秒)
通过Agent工具传入prompt:
"Run the build-class-index.sh script from this skill directory
Report when indexing is complete."
等待子Agent执行完成后再继续后续流程
fi
**注意:** 索引构建任务会派发给子Agent执行,以保证主会话的响应速度。该脚本使用8个并行工作进程,通常可在60秒内完成。Step 3: Search the Index
步骤3:搜索索引
Search is instant (just grep on a text file):
For fully qualified class name:
bash
grep "com/fasterxml/jackson/databind/ObjectMapper\.class" "$INDEX"For simple class name:
bash
grep -i "/ObjectMapper\.class" "$INDEX"For partial pattern:
bash
grep -i "jackson.*ObjectMapper\.class" "$INDEX"搜索是即时完成的(仅需对文本文件执行grep操作):
全限定类名搜索:
bash
grep "com/fasterxml/jackson/databind/ObjectMapper\.class" "$INDEX"简单类名搜索:
bash
grep -i "/ObjectMapper\.class" "$INDEX"部分模式搜索:
bash
grep -i "jackson.*ObjectMapper\.class" "$INDEX"Step 4: Check Local Build Output
步骤4:检查本地构建输出
Also search project build directories for classes:
bash
find . -path "*/target/classes/*ClassName.class" 2>/dev/null同时在项目构建目录中搜索类文件:
bash
find . -path "*/target/classes/*ClassName.class" 2>/dev/nullStep 5: Present Results
步骤5:展示结果
Format output to show:
-
Class path within JAR - The full package path
-
JAR file path - Highlight groupId, artifactId, version from path
-
Maven coordinates - Extract from JAR path:
~/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.15.0/jackson-databind-2.15.0.jarBecomes:com.fasterxml.jackson.core:jackson-databind:2.15.0 -
Conflict warnings - If multiple versions exist, flag as potential classpath issue
Example output format:
Found in 2 locations:
1. com/fasterxml/jackson/databind/ObjectMapper.class
JAR: com.fasterxml.jackson.core:jackson-databind:2.15.0
Path: ~/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.15.0/jackson-databind-2.15.0.jar
2. com/fasterxml/jackson/databind/ObjectMapper.class
JAR: com.fasterxml.jackson.core:jackson-databind:2.14.2
Path: ~/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.14.2/jackson-databind-2.14.2.jar
⚠️ WARNING: Multiple versions detected - potential classpath conflict格式化输出以下内容:
-
JAR内的类路径 - 完整包路径
-
JAR文件路径 - 高亮显示路径中的groupId、artifactId、version
-
Maven坐标 - 从JAR路径中提取:
~/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.15.0/jackson-databind-2.15.0.jar转换为:com.fasterxml.jackson.core:jackson-databind:2.15.0 -
冲突警告 - 如果存在多个版本,标记为潜在类路径问题
输出格式示例:
Found in 2 locations:
1. com/fasterxml/jackson/databind/ObjectMapper.class
JAR: com.fasterxml.jackson.core:jackson-databind:2.15.0
Path: ~/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.15.0/jackson-databind-2.15.0.jar
2. com/fasterxml/jackson/databind/ObjectMapper.class
JAR: com.fasterxml.jackson.core:jackson-databind:2.14.2
Path: ~/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.14.2/jackson-databind-2.14.2.jar
⚠️ WARNING: Multiple versions detected - potential classpath conflictStep 6: Handle No Results
步骤6:无结果处理
If search returns nothing:
- Rebuild index - Run the build-class-index.sh script from this skill directory
- Check spelling - Suggest corrected class name
- Verify dependency - Class might not be in local repo, suggest
mvn dependency:resolve - Broaden search - Try searching for just the class name without package
如果搜索没有返回结果:
- 重建索引 - 执行本技能目录下的build-class-index.sh脚本
- 检查拼写 - 建议更正类名拼写
- 验证依赖 - 类可能不在本地仓库中,建议执行
mvn dependency:resolve - 扩大搜索范围 - 尝试不带包名仅搜索类名
Index Details
索引详情
What's indexed:
- All files in
.class~/.m2/repository/**/*.jar - Excludes: ,
-sources.jar,-javadoc.jar,-tests.jar-test-*.jar - Excludes: Inner classes (),
$,module-infopackage-info
Index format:
com/example/MyClass.class\t/path/to/artifact-1.0.0.jarBuild time: ~30-60 seconds with 8 parallel workers
Size: Varies by repository size (typically 5-20 MB)
索引内容:
- 所有中的
~/.m2/repository/**/*.jar文件.class - 排除:、
-sources.jar、-javadoc.jar、-tests.jar-test-*.jar - 排除:内部类(含)、
$、module-infopackage-info
索引格式:
com/example/MyClass.class\t/path/to/artifact-1.0.0.jar构建耗时: 8个并行工作进程下约30-60秒
大小: 随仓库大小变化(通常为5-20MB)
Tips
使用提示
- Index is automatically refreshed every 7 days
- For inner classes, search JAR directly:
jar tf /path/to.jar | grep ClassName - Use flag for case-insensitive searches
-i - The index uses 8 parallel workers for fast building
- Subagent dispatch keeps main conversation responsive during index builds
- 索引每7天自动刷新一次
- 如需搜索内部类,可直接查询JAR:
jar tf /path/to.jar | grep ClassName - 使用参数执行大小写不敏感的搜索
-i - 索引构建使用8个并行进程提升速度
- 子Agent派发机制保证索引构建过程中主会话仍可响应
Supporting Tool
配套工具
The index is built by (included in this skill directory):
build-class-index.shbash
#!/bin/bash
INDEX_FILE="${1:-$HOME/.cache/quarkusdev-skills/class-index.txt}"
REPO_DIR="${2:-$HOME/.m2/repository}"
find "$REPO_DIR" -name "*.jar" \
-not -name "*-sources*" \
-not -name "*-javadoc*" \
-not -name "*-tests*" \
-not -name "*-test-*" | \
xargs -P 8 -I{} sh -c '
jar tf "$1" 2>/dev/null | grep "\.class$" | grep -v "module-info\|package-info" | while read cls; do
printf "%s\t%s\n" "$cls" "$1"
done
' _ {} > "$INDEX_FILE"索引由脚本构建(包含在本技能目录中):
build-class-index.shbash
#!/bin/bash
INDEX_FILE="${1:-$HOME/.cache/quarkusdev-skills/class-index.txt}"
REPO_DIR="${2:-$HOME/.m2/repository}"
find "$REPO_DIR" -name "*.jar" \
-not -name "*-sources*" \
-not -name "*-javadoc*" \
-not -name "*-tests*" \
-not -name "*-test-*" | \
xargs -P 8 -I{} sh -c '
jar tf "$1" 2>/dev/null | grep "\.class$" | grep -v "module-info\|package-info" | while read cls; do
printf "%s\t%s\n" "$cls" "$1"
done
' _ {} > "$INDEX_FILE"Platform Notes
平台说明
This skill works with:
- Claude Code: Direct execution via Bash/Agent tools
- Gemini CLI: Use equivalent bash/file tools
- Codex: Use RunBash/SubAgent equivalents
The script is platform-independent (standard bash).
build-class-index.sh本技能支持以下平台:
- Claude Code:通过Bash/Agent工具直接执行
- Gemini CLI:使用等效的bash/file工具执行
- Codex:使用RunBash/SubAgent等效功能执行
build-class-index.sh