Reputation: 1274
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);
}
}
Upvotes: 65
Views: 52533
Reputation: 4775
In case someone uses IDEA, -ea
is enabled by default in some IDEA versions, but disabled in others. To manually configure it, it is under run
-> edit configuration
-> vm option
Upvotes: 0
Reputation: 66637
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.
Upvotes: 2
Reputation: 19776
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:
Upvotes: 49
Reputation: 718758
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.
Upvotes: 2
Reputation: 13151
To be specific:
Run->run configuration
java application
in left nav pan.select New
.Arguments
tab-ea
in VM arguments.Upvotes: 106
Reputation: 117589
Run
-> Run Configurations...
.Arguments
tab.-ea
to VM arguments
.Apply
.Run
.Upvotes: 9