Java 在 IntelliJ IDEA 中在哪里添加编译器选项,如 -ea?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18168257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where to add compiler options like -ea in IntelliJ IDEA?
提问by duleshi
I want to add the -ea
option. I set it in Project Settings
--> Compiler
--> Java Compiler
: Additional command line parameters
.
我想添加-ea
选项。我将它设置为Project Settings
--> Compiler
--> Java Compiler
: Additional command line parameters
。
But it caused a make error: invalid flag: -ea
.
P.S.: the above error message may not be the same as yours, because IntelliJ showed error in my native language, not English. I translated it into English.
但它导致了一个 make 错误:invalid flag: -ea
. PS:上面的错误信息可能和你的不一样,因为 IntelliJ 用我的母语而不是英语显示错误。我把它翻译成英文。
采纳答案by Dev
The -ea
option to enable assertions is passed to the JVM not to the compiler. Add it as a VM option for your runtime configuration.
-ea
启用断言的选项传递给 JVM,而不是传递给编译器。将其添加为运行时配置的 VM 选项。
Specific location in the menu: Run > Edit Configurations... > Configuration > VM options:
菜单中的特定位置:运行 > 编辑配置... > 配置 > VM 选项:
回答by neo
You can also make IntelliJ IDEA support assertions by default by changing the default Application configuration:
您还可以通过更改默认应用程序配置使 IntelliJ IDEA 默认支持断言:
In the top menu, press Run > Edit Configurations > Defaults > Application > VM options.
在顶部菜单中,按Run > Edit Configurations > Defaults > Application > VM options。
To enable the assertion feature for all application, you could just fill the VM options
with -ea
为了让所有应用程序的断言功能,你可以只填写VM options
与-ea