I'm running Eclipse Galileo. How do I enable assertions in Eclipse?
As suggested by other sites, I've tried adding the arguments: -ea
. I have also tried changing the compiler compliance level to 1.4
. Neither of those suggestions worked.
I'm running Eclipse Galileo. How do I enable assertions in Eclipse?
As suggested by other sites, I've tried adding the arguments: -ea
. I have also tried changing the compiler compliance level to 1.4
. Neither of those suggestions worked.
You want to enable assertions for an application you're running from Eclipse? I usually just add -ea to the command line parameters in the "Run As" profile.
If you want to solve this issue globally for all JUnit tests then go to
Preferences > Java > JUnit
and at the top click the checkbox for "Add 'ea' to VM arguments when creating new JUnit launch configuration" Now Eclipse won't bug you for every new test you want to run. For existing tests you have to remove their's run configurations inRun Configuration > JUnit
.On maven projects you can run main method with auto-magic classpath by:
In linux/eclipse you can add terminal window with bash for more convenient use.
Run
, and then to the menu itemRun Configurations
.In the left panel, go to
Java Application
, and then go toAssertions
.In the right panel, choose the tab
Arguments
.Under the field for
VM arguments
, type-ea
to enable assertions.Apply
and thenRun
button.To globally set it as the default for everything:
Go to menu
Window
(if you are on Windows), or go to menuEclipse
(if you are on Mac). For Linux it might be something similar.Go to
Preferences
.Choose
Java
, and thenInstalled JREs
from the left panel.Select your JRE, and then click the
Edit...
button in the right panel.In the
Default VM arguments
field, add-ea
.To do this globally for all Java runs, edit the Installed JREs properties.
For example: Windows -> Preferences -> highlight the default JRE -> click Edit... -> In the Default VM arguments input box, enter -ea -> click the finish button.
This worked on Eclipse Kepler SR2.