Enabling Assertions from the Command Line

The command line options -ea and -da allow you to enable and disable assertion in a package subtree or in a class. Here are several examples of the switches. Enable assertions in all non-system classes:
java -ea MyApp
Enable assertions in all classes in the unnamed package:
java -ea:... MyApp
Enable assertions in all classes in a package subtree:
java -ea:com.mycompany... MyApp
Enable assertions in a particular class:
java -ea:com.mycompany.MyCompany MyApp
Disable assertions in all classes in a package subtree:
java -da:com.mycompany... MyApp
Disable assertions in a particular class:
java -da:com.mycompany.MyClass MyApp
Multiple assertion switches on the command line are processed from left to right. Enable assertions in all classes in a package subtree except for one class:
java -ea:com.mycompany... -da:com.mycompany.MyClass MyApp

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.