aspose file tools*
The moose likes Tomcat and the fly likes How to enable JDK 1.4 assertions in Tomcat? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to enable JDK 1.4 assertions in Tomcat?" Watch "How to enable JDK 1.4 assertions in Tomcat?" New topic
Author

How to enable JDK 1.4 assertions in Tomcat?

Thomas Wermter
Greenhorn

Joined: May 08, 2003
Posts: 4
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

Joined: Oct 12, 2001
Posts: 1179

in 'setclasspath.bat' you need to insert this line:
Rene


Regards, Rene Larsen
Dropbox Invite
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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

Joined: May 08, 2003
Posts: 4
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

Joined: Mar 22, 2000
Posts: 12803
    
    5
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

Joined: Jun 25, 2001
Posts: 16137
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Did you remember to compile your servlet with the option '-source 1.4'?

Rene
Thomas Wermter
Greenhorn

Joined: May 08, 2003
Posts: 4
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to enable JDK 1.4 assertions in Tomcat?