maven项目src/main/java包compilation error

Maven项目编译错误解决
本文介绍了一个Maven项目中因源文件夹路径设置不当导致的编译错误,并提供了在Eclipse环境中调整源文件夹名称的具体步骤。

问题描述:

maven项目目录结构如下--》


example_project

---src/main/java

A.java

---src/test/java

---usecase/example

B.java


假如  src/main/java中的A.java类中存在usecase/example包中的B.java对象


则运行maven clean package时:

会报 COMPILATION ERROR,

Can't find class B.java


原因::maven package经历的阶段clean --> 编译src/main/java-->编译src/test/java-->test-->package

所以如果A类中存在B类的对象,则由于编译顺序的原因,肯定会报找不到B.java的error.


如果类之间的引用关系不能变,,

则可以修改A.java所在的源文件夹的文件名。

在Eclipse中的修改方法::

example_project:右键--》Build Path-->Build Path Configuration --->source -->双击目标文件夹--修改名称。

zhouweixiang@KI-ZJ-2961:~/addSecret/fastzip-test$ mvn clean compile [INFO] Scanning for projects... [INFO] [INFO] ----------------------< com.example:fastzip-test >---------------------- [INFO] Building fastzip-test 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ fastzip-test --- [INFO] Deleting /home/zhouweixiang/addSecret/fastzip-test/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ fastzip-test --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory /home/zhouweixiang/addSecret/fastzip-test/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ fastzip-test --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to /home/zhouweixiang/addSecret/fastzip-test/target/classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[147,23] 需要<标识符> [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[147,24] 非法的类型开始 [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[151,20] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[153,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[154,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[156,13] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[158,13] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[160,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[162,5] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[168,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[169,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[171,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[172,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[174,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[175,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[176,5] 需要class, interface或enum [INFO] 16 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.770 s [INFO] Finished at: 2025-08-19T11:35:04+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project fastzip-test: Compilation failure: Compilation failure: [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[147,23] 需要<标识符> [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[147,24] 非法的类型开始 [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[151,20] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[153,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[154,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[156,13] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[158,13] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[160,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[162,5] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[168,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[169,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[171,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[172,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[174,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[175,9] 需要class, interface或enum [ERROR] /home/zhouweixiang/addSecret/fastzip-test/src/main/java/com/example/CompressionRunner.java:[176,5] 需要class, interface或enum [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException zhouweixiang@KI-ZJ-2961:~/addSecret/fastzip-test$
08-20
// 文件路径: src/main/java/com/example/callback/ProgressCallback.java package com.example.callback; public interface ProgressCallback { void onProgress(int progress, int total); } zhouweixiang@KI-ZJ-2961:~/addSecret/zip-generator$ mvn clean compile [INFO] Scanning for projects... [INFO] [INFO] -------------------< com.example:compress-benchmark >------------------- [INFO] Building compress-benchmark 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ compress-benchmark --- [INFO] Deleting /home/zhouweixiang/addSecret/zip-generator/target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ compress-benchmark --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /home/zhouweixiang/addSecret/zip-generator/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ compress-benchmark --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 5 source files to /home/zhouweixiang/addSecret/zip-generator/target/classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[4,28] 无法访问com.example.callback.ProgressCallback 错误的源文件: /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/callback/ProgressCallback.java 文件不含类com.example.callback.ProgressCallback 请删除该文件或确保该文件位于正确的源路径子目录中。 [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[31,74] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[54,70] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[94,34] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[25,100] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.USBOfflineUpdater [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[27,17] 方法不会覆盖或实现超类型的方法 [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[46,112] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.USBOfflineUpdater [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[48,17] 方法不会覆盖或实现超类型的方法 [INFO] 8 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.990 s [INFO] Finished at: 2025-08-27T10:24:19+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project compress-benchmark: Compilation failure: Compilation failure: [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[4,28] 无法访问com.example.callback.ProgressCallback [ERROR] 错误的源文件: /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/callback/ProgressCallback.java [ERROR] 文件不含类com.example.callback.ProgressCallback [ERROR] 请删除该文件或确保该文件位于正确的源路径子目录中。 [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[31,74] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[54,70] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[94,34] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[25,100] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.USBOfflineUpdater [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[27,17] 方法不会覆盖或实现超类型的方法 [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[46,112] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.USBOfflineUpdater [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[48,17] 方法不会覆盖或实现超类型的方法 [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
最新发布
08-28
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project ship: Compilation failure: Compilation failure: [ERROR] /D:/SourceTreeRepo/xm-manager/src/main/java/com/wj/modules/remoteSignature/util/FileUtils.java:[19,12] 找不到符号 [ERROR] 符号: 类 BASE64Decoder [ERROR] 位置: 类 com.wj.modules.remoteSignature.util.FileUtils [ERROR] /D:/SourceTreeRepo/xm-manager/src/main/java/com/wj/modules/remoteSignature/util/FileUtils.java:[21,19] 找不到符号 [ERROR] 符号: 类 BASE64Decoder [ERROR] 位置: 类 com.wj.modules.remoteSignature.util.FileUtils [ERROR] /D:/SourceTreeRepo/xm-manager/src/main/java/com/wj/modules/remoteSignature/controller/PdfController.java:[54,16] 找不到符号 [ERROR] 符号: 类 BASE64Decoder [ERROR] 位置: 程序 sun.misc [ERROR] /D:/SourceTreeRepo/xm-manager/src/main/java/com/wj/modules/remoteSignature/controller/PdfController.java:[304,12] 找不到符号 [ERROR] 符号: 类 BASE64Decoder [ERROR] 位置: 类 com.wj.modules.remoteSignature.controller.PdfController [ERROR] /D:/SourceTreeRepo/xm-manager/src/main/java/com/wj/modules/send/service/impl/SendExchangeServiceImpl.java:[29,16] 找不到符号 [ERROR] 符号: 类 BASE64Decoder [ERROR] 位置: 程序 sun.misc [ERROR] /D:/SourceTreeRepo/xm-manager/src/main/java/com/wj/modules/remoteSignature/util/FileUtils.java:[19,40] 找不到符号 [ERROR] 符号: 类 BASE64Decoder [ERROR] 位置: 类 com.wj.modules.remoteSignature.util.FileUtils [ERROR] /D:/SourceTreeRepo/xm-manager/src/main/java/com/wj/modules/remoteSignature/util/FileUtils.java:[90,9] 找不到符号 [ERROR] 符号: 类 BASE64Decoder [ERROR] 位置: 类 com.wj.modules.remoteSignature.util.FileUtils [ERROR] /D:/SourceTreeRepo/xm-manager/src/main/java/com/wj/modules/remoteSignature/util/FileUtils.java:[90,37] 找不到符号 [ERROR] 符号: 类 BASE64Decoder [ERROR] 位置: 类 com.wj.modules.remoteSignature.util.FileUtils [ERROR] /D:/SourceTreeRepo/xm-manager/src/main/java/com/wj/modules/document/service/impl/RestService.java:[48,63] 找不到符号 [ERROR] 符号: 方法 getValue() [ERROR] 位置: 类型为com.
03-12
zhouweixiang@KI-ZJ-2961:~/addSecret/zip-generator$ mvn compile [INFO] Scanning for projects... [INFO] [INFO] -------------------< com.example:compress-benchmark >------------------- [INFO] Building compress-benchmark 1.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ compress-benchmark --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /home/zhouweixiang/addSecret/zip-generator/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ compress-benchmark --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 5 source files to /home/zhouweixiang/addSecret/zip-generator/target/classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[4,28] 无法访问com.example.callback.ProgressCallback 错误的源文件: /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/callback/ProgressCallback.java 文件不含类com.example.callback.ProgressCallback 请删除该文件或确保该文件位于正确的源路径子目录中。 [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[31,74] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[54,70] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[94,34] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[25,100] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.USBOfflineUpdater [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[27,17] 方法不会覆盖或实现超类型的方法 [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[46,112] 找不到符号 符号: 类 ProgressCallback 位置: 类 com.example.USBOfflineUpdater [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[48,17] 方法不会覆盖或实现超类型的方法 [INFO] 8 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.691 s [INFO] Finished at: 2025-08-27T10:21:45+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project compress-benchmark: Compilation failure: Compilation failure: [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[4,28] 无法访问com.example.callback.ProgressCallback [ERROR] 错误的源文件: /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/callback/ProgressCallback.java [ERROR] 文件不含类com.example.callback.ProgressCallback [ERROR] 请删除该文件或确保该文件位于正确的源路径子目录中。 [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[31,74] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[54,70] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/FileUtilszwx.java:[94,34] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.FileUtilszwx [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[25,100] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.USBOfflineUpdater [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[27,17] 方法不会覆盖或实现超类型的方法 [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[46,112] 找不到符号 [ERROR] 符号: 类 ProgressCallback [ERROR] 位置: 类 com.example.USBOfflineUpdater [ERROR] /home/zhouweixiang/addSecret/zip-generator/src/main/java/com/example/USBOfflineUpdater.java:[48,17] 方法不会覆盖或实现超类型的方法 [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException zhouweixiang@KI-ZJ-2961:~/addSecret/zip-generator$ tree . ├── pom.xml ├── src │ ├── main │ │ └── java │ │ └── com │ │ └── example │ │ ├── callback │ │ │ └── ProgressCallback.java │ │ ├── FileUtilszwx.java │ │ ├── USBOfflineUpdater.java │ │ ├── ZipCompressionBenchmark.java │ │ └── ZipWithSignatureGenerator.java │ └── test │ └── java │ └── com └── target ├── classes │ └── com │ └── example │ ├── callback │ ├── FileUtilszwx.class │ ├── USBOfflineUpdater.class │ └── ZipCompressionBenchmark.class ├── generated-sources │ └── annotations ├── maven-status │ └── maven-compiler-plugin │ └── compile │ └── default-compile │ ├── createdFiles.lst │ └── inputFiles.lst └── test-classes └── com 22 directories, 11 files zhouweixiang@KI-ZJ-2961:~/addSecret/zip-generator$
08-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值