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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:58:39  来源:igfitidea点击:

Where to add compiler options like -ea in IntelliJ IDEA?

javaintellij-idea

提问by duleshi

I want to add the -eaoption. 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 -eaoption 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 选项

Where to put the <code>-ea</code>flag

<code>-ea</code>标志放在哪里

回答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 optionswith -ea

为了让所有应用程序的断言功能,你可以只填写VM options-ea