JavaFAQ Home » JSP, Servlets
Question: Assertions do not work on my Tomcat 5.15 on Linux! I use JDK 1.5_05, used many code examples of this Java feature - assertion, nothing works!!!!!
What tool could I use to find out the reason of the problem? Or just it is Tomcat that does not support assertions?
Answer: Tomcat server supports assertions, but you need explicitly enable assertions in the JVM. You have to find catalina.sh file (on UNIX/Linux/Solaris OS) in Tomcat's "bin" directory and locate a line with "JAVA_OPTS".
This variable is used to pass different options to JVM during start up. For example:
JAVA_OPTS = "-Xms128m -Xmx512m" add options to manage memory.
Be aware that assertions can be enabled/disabled in general, for all classes and packages by switch:
"-ea" or "-enableassertions"
"-da" or "-disableassertions"
If you add a package, sub package or class name after the switch you will limit the area where switch is applied. It works both for enable and disable commands. Append the switch for assertions to the line JAVA_OPTS, for example for your class only:
JAVA_OPTS = "-Xms128m -Xmx512m -ea MyClass "
Do not forget to use the full class name, including package name and sub packages if the class belongs to some package.
One more general notice: you have to use the switch before any class loaded! For example:
java -ea MyClass, not
java MyClass -ea
Printer Friendly Page
Send to a Friend
Search here again if you need more info!