如何解决以下警告
warning: [options] bootstrap class path not set in conjunction with -source 8
使用内部JavaCompiler
时是什么?
示例代码(从我的源代码中稍作修改):
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, compilerOptions, null, javaFileObjects);
task.call();
我尝试的显而易见的事情是在上面的示例代码中向-bootclasspath
提供compilerOptions
。但是您只能在Option.OptionGroup.BASIC
组中提供选项(而不能)。
编辑: 更多信息:我正在使用OpenJdk11,并且收到所有10级以下源的警告。
答案 0 :(得分:1)
从编译器中,您可以获取文件管理器来设置bootclasspath:
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
List<File> filePaths = ...;
fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, filePaths);
https://docs.oracle.com/javase/8/docs/api/javax/tools/StandardLocation.html#PLATFORM_CLASS_PATH