How to pass compiler options when running a single-file source-code Java program?
Gunnar Morling
gunnar at hibernate.org
Sun Dec 16 10:04:17 UTC 2018
Hi,
I'd like to use JEP 330 [1] to run a single-file source-code program
with Java (>= 11).
Doing so, I'd like to pass options understood by javac but not by the
runtime (java), e.g. -XDsuppressNotes. But this causes e.g. the
following invocation to fail:
java --enable-preview --source=12 -XDsuppressNotes Test.java
Unrecognized option: -XDsuppressNotes
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
There's this related sentence in the JEP:
> The source-launcher implementation class has access to any relevant
> command-line options, such as those to define the class path, module path,
> and the module graph, and passes those options to the compiler to configure
> the compilation environment.
So I'd expect an option such as -XDsuppressNotes to be propagated, but
it seems there's no authoritative list of options propagated to javac
defined.
Is there any way to pass this option when implicitly invoking the
compiler through the java command in this case?
Thanks,
--Gunnar
[1] https://openjdk.java.net/jeps/330
More information about the compiler-dev
mailing list