java
build_error
ai_generated
true
编译失败:包 com.example.util 不存在
Compilation failure: package com.example.util does not exist
ID: java/maven-compilation-package-not-exists
80%修复率
85%置信度
0证据数
2024-02-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 8+ | active | — | — | — |
根因分析
类路径中缺少必需的 Java 包,通常是由于缺少依赖或模块路径不正确。
English
A required Java package is missing from the classpath, often due to a missing dependency or incorrect module path.
解决方案
-
95% 成功率 Add the correct dependency to pom.xml
<dependency><groupId>com.example</groupId><artifactId>example-utils</artifactId><version>1.0.0</version></dependency>
-
80% 成功率 Use mvn dependency:copy-dependencies to verify classpath
mvn dependency:copy-dependencies -DoutputDirectory=target/lib
无效尝试
常见但无效的做法:
-
Adding a random dependency with similar groupId but different artifactId
90% 失败
The package name is specific to the correct artifact; a different artifact may not contain it.
-
Manually copying the jar file to the project's lib folder without updating pom.xml
85% 失败
Maven does not automatically include local jars unless configured as system scope.