• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to enable JDK 1.4 assertions in Tomcat?

 
Thomas Wermter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to use the assert statement from JDK 1.4 in my servlets in Tomcat 4.1.24 (Win). I know I have to enable it by a command line parameter -ea. But how do I tell this my Tomcat server?
I tried to set the CATALINA_OPTS shell variable
(CATALINA_OPTS="-ea") but it didn't work.
Any ideas?
Thanks,
Tom
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in 'setclasspath.bat' you need to insert this line:
Rene
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The potential problem with this: If your servlet throws an assertion error, is the container designed to handle it? I think not, because assertions aren't meant to be handled by code (even though they can be).

So... umm.... won't that cause the current thread to die with an assertion error? How would the container notify the browser that something had gone wrong? Would it perhaps kill the container?

I'd be interested to hear your results...

Also... moving this from Servlets -> Apache/Tomcat
 
Thomas Wermter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, sorry for posting to the wrong forum.
@Rene: Unfortunately, it didn't work. Is this all you did to get it working?
BTW: Is there a difference between CATALINA_OPTS and JAVA_OPTS? Both are used as Java runtime options.
@Mike: The webapp should stop with an assertion error, because then there went something completely wrong! What I want to do is the following:
Replace:

with:

I'd prefer that my container isn't dying in this case.
Tom
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet container catches every Throwable that a request Thread can throw so don't worry about an AssertionError stopping the whole servlet engine.
Bill
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18281
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:
The servlet container catches every Throwable that a request Thread can throw so don't worry about an AssertionError stopping the whole servlet engine.
Bill

In other words, you can expect to see the stack trace come back in the browser window. The response code is probably going to be "500".
Just as a matter of good practice, for production I'd put an intercept that logs the stack trace (actually I believe it should be already) and display a "System error, webmaster notified" page.
Having a stack dump come back to a user make your app look less reliable (admittedly, if it died, it is less reliable, sut still...). Also, that's information that you probably don't want unfriendly eyes to see.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you remember to compile your servlet with the option '-source 1.4'?

Rene
 
Thomas Wermter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Solved it - at least partly:
In windows you are able to start Tomcat in 2 ways:
1. Start->Programs->Tomcat-> Start Tomcat
which does the following:
C:java.exe -jar -Duser.dir="F:\Tomcat 4.1" "F:\Tomcat 4.1\bin\bootstrap.jar" start
2. Over the command line like this:
F:\Tomcat 4.1\bin\startup.bat
I used version 1. Obviously, I have to enter the "-ea" option there. And yes, it worked.
Then I was curious if it'll work if I use version 2. Surprisingly, no web application was available (even the examples weren't) and I was not able to login to the manager console...
How do you start your Tomcats under Windows? Do know this problem?
BTW, thank you for your hints so far.
Tom
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic