I want to load a Java version specific JavaCompiler
.
This is how I take compiler instance currently:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
My aim is to compile a "user Java code" according to the Java version (Java 8 or Java 13) in which it is originally written.
I am building my whole source code in Java 8.
Hence compiler
instance that I am getting will be Java 8 specific and I can not compile Java 13 code (correct me if I am wrong).
I have both Java 8 and Java 13 installed.
I read below statement from this article
The ToolProvider locates the default compiler in this case. It is also possible to locate alternative compilers or tools by using service provider mechanism.
Is there any way from which I can load Java version specific Java compiler? Is there a workaround for it?
Or, if I build project using Java 13, can I then compile version-specific using --target
or --source
or --release
arguments of Java 13 compiler?