0

How can you resolve the following warning

warning: [options] bootstrap class path not set in conjunction with -source 8

when using the internal JavaCompiler?

Example code (slightly modified from my source):

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 
JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, compilerOptions, null, javaFileObjects);
task.call();

The obvious thing I tried was to supply -bootclasspath to compilerOptions in the example code above. But you can only supply options in the Option.OptionGroup.BASIC group (and it is not).

Edit: Some more info: I am using OpenJdk11 and I get the warning for all sources up to 10.

osundblad
  • 2,675
  • 1
  • 29
  • 34
  • I based that the option is not available on `ToolProvider.getSystemJavaCompiler().isSupportedOption(option)` maybe that is wrong? – osundblad Dec 26 '18 at 16:03

1 Answers1

1

From the compiler, you can get a file manager to set the 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/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

Antonio
  • 88
  • 6