【问题标题】:How to set bootclasspath when using the "internal" JavaCompiler使用“内部”JavaCompiler 时如何设置引导类路径
【发布时间】:2019-05-24 20:13:07
【问题描述】:

如何解决以下警告

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 个。

【问题讨论】:

  • 我认为ToolProvider.getSystemJavaCompiler().isSupportedOption(option) 上没有该选项可能是错误的?

标签: java javacompiler


【解决方案1】:

从编译器,你可以得到一个文件管理器来设置引导类路径:

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/StandardJavaFileManager.html#setLocation-javax.tools.JavaFileManager.Location-java.lang.Iterable-

https://docs.oracle.com/javase/8/docs/api/javax/tools/StandardLocation.html#PLATFORM_CLASS_PATH

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 2012-03-15
    • 2014-03-31
    相关资源
    最近更新 更多