首页 > 解决方案 > 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(抛出时)都应该被catchfor 子句捕获ExecutionException,那么问题是什么?

据我所知,maven-compiler-plugin似乎认为NotFoundException是一个Throwable. NotFoundException在我的代码(项目)中定义,所以maven-compiler-plugin应该知道它......

编译器插件的源和目标定义为1.8. 有 Java 版本1.8.0_181。尝试使用maven-compiler-pluginversion 3.8.0,得到相同的结果。

标签: javaeclipsemavenmaven-compiler-plugin

解决方案


推荐阅读