JavaFX录屏项目出现module not found错误,已声明依赖
解决monte-screen-recorder模块找不到的问题
针对你遇到的java: module not found: monte.screen.recorder错误,按以下步骤排查:
1. 确认Maven依赖配置正确性
首先检查pom.xml中的依赖是否完全正确,当前有效的monte-screen-recorder依赖坐标为:
<dependency> <groupId>com.github.stephenc.monte</groupId> <artifactId>monte-screen-recorder</artifactId> <version>0.7.7.0</version> </dependency>
执行mvn clean install重新拉取依赖,确保本地仓库中存在完整的JAR包。
2. 处理非模块化依赖的加载问题
monte-screen-recorder属于非模块化JAR(无内置module-info.class),它的自动模块名为monte.screen.recorder。若声明requires monte.screen.recorder;仍报错,需在编译和运行阶段强制添加模块:
- 在Maven编译插件中配置VM参数:
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>11</source> <!-- 替换为你的Java版本 --> <target>11</target> <compilerArgs> <arg>--add-modules</arg> <arg>monte.screen.recorder</arg> </compilerArgs> </configuration> </plugin> </plugins> </build> - 运行时也需添加VM参数:
--add-modules monte.screen.recorder
3. 调整module-info.java声明
如果是编译期检查报错,可尝试将声明改为:
requires static monte.screen.recorder;
static关键字表示该模块仅在编译期依赖,运行时通过自动模块机制加载。
4. 清理IDE缓存
若使用IntelliJ IDEA或Eclipse,执行以下操作消除缓存影响:
- IntelliJ:
File -> Invalidate Caches... -> Invalidate and Restart - Eclipse:
Project -> Clean...,并重新导入Maven项目
5. 手动验证JAR模块属性
找到本地Maven仓库中的monte-screen-recorder-0.7.7.0.jar,解压后查看META-INF/MANIFEST.MF:
- 若存在
Automatic-Module-Name属性,直接使用该属性值作为模块名 - 若不存在,自动模块名即为
monte.screen.recorder(由文件名monte-screen-recorder转换而来)
内容的提问来源于stack exchange,提问作者Anup Panchal
相关产品推荐
相关产品推荐

