java - maven-compiler-plugin 无法编译 Eclipse 没有问题的文件
问题描述
Eclipse 编译以下代码没有任何问题,而当mvn
尝试编译此代码时,会导致编译失败:
try {
// Distribution.rep().get(id) returns a java.util.Optional
Distribution updated = Distribution.rep().transact(() -> {
Distribution distro = Distribution.rep().get(id).orElseThrow(() -> {
throw new NotFoundException("Couldn't find Distribution with ID '%s'.", id);
});
// Other stuff...
});
rs.setData(updated);
} catch (ExecutionException e) {
// Handle the error
} catch (Exception e) {
// Handle the exception
}
抛出的错误maven-compiler-plugin:3.1
是:
unreported exception java.lang.Throwable; must be caught or declared to be thrown
NotFoundException extends RuntimeException
. 该方法在抛出它们之前transact
将所有运行时 (?) 异常包装在 an 中。ExecutionException
无论哪种方式,this NotFoundException
(抛出时)都应该被catch
for 子句捕获ExecutionException
,那么问题是什么?
据我所知,maven-compiler-plugin
似乎认为NotFoundException
是一个Throwable
. NotFoundException
在我的代码(项目)中定义,所以maven-compiler-plugin
应该知道它......
编译器插件的源和目标定义为1.8
. 有 Java 版本1.8.0_181
。尝试使用maven-compiler-plugin
version 3.8.0
,得到相同的结果。
解决方案
推荐阅读
- amazon-web-services - com.amazonaws.SdkClientException:无法计算 MD5 哈希:/home/bharath/Documents/demo/demo.txt(没有这样的文件或目录)
- scala - 您可以使用 alpakka HDFS 连接器附加到文件吗?
- javascript - 行在 html 中收缩和扩展
- html - 在示例中,react redux 中 api 调用的 400 错误工作正常
- mysql - 如何正确格式化重叠的 mySQL IN 和 NOT IN 条件
- css - 像普通的 img 标签一样调整背景图像的大小
- javascript - 转义 javascript 中的正则表达式特殊字符,但仍保留匹配关键字的字符串完整性
- c# - WPF、C#、MVVM 在模型中静态变量的变化中动态通知 ViewModel
- javascript - 为什么我不能将 `push` 作为 foreach 函数传递?
- javascript - three.js 中的样条偏移