How to enable the Java keyword assert in Eclipse program-wise?
Solution 1
To be specific:
- Go to
Run->run configuration
- select
java application
in left nav pan. - right click and
select New
. - select
Arguments
tab - Add
-ea
in VM arguments.
Solution 2
If anyone wants to enable assertions by default (in contrast to enabling them for just a single run configuration), it is possible with the following steps:
- Window (menu bar)
- Preferences
- Java
- Installed JREs
- Select your JRE/JDK
- Press Edit...
- Default VM arguments
- Add -ea
Solution 3
- Form the menu bar, select
Run
->Run Configurations...
. - Select
Arguments
tab. - Add
-ea
toVM arguments
. - Click
Apply
. - Click
Run
.
Solution 4
You need to go to run configurations and add vm arguments as "-enableassertions" (or) "-ea"
After that when you run code with assert statement, you will see assert in action.
Solution 5
Java introduced the assert
keyword, so the way to enable source-level support is to make sure that Eclipse's Java compliance level is 1.4 or higher. (The chances are that the compliance level is already higher than that ...)
To cause a Java application launched from Eclipsed to run with assertion checking enabled, add the "-ea" argument to the VM arguments in the launcher configuration's "Arguments" tab.
Siva Kumar Reddy G
Hello, I love to learn new technologies and explore. Now, I am working as a devops consultant.
Updated on July 08, 2022Comments
-
Siva Kumar Reddy G almost 2 years
How can I enable the
assert
keyword in Eclipse?public class A { public static void main(String ... args) { System.out.println(1); assert false; System.out.println(2); } }
-
Siva Kumar Reddy G almost 12 yearsThank You ... @thinksteep your answer is very helpful to me .. .
-
Siva Kumar Reddy G almost 12 yearsThank u for detail explaination with picture
-
Haravikk almost 10 yearsThis is a very useful supplement; I can't believe I've been adding
-ea
to every run configuration (specifically while debugging) as assertions are such a handy, yet underused, feature during development. -
Tahlor over 6 yearsThis had no effect for me.
-
Ohad Kravchick over 6 years-enableassertions
-
kosa over 6 years@OhadKravchick you caught it after almost 5 years, ha ha. Updated answer. Thanks for the comment!