Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Assertions do not work in Tomcat and Java!

JavaFAQ Home » JSP, Servlets Go to all tips in JSP, Servlets

Bookmark and Share

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  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy