Execute code on Deployment

I have been using Netbeans 5.5 to create some JSP pages. What can I do to make sure some code is executed when the app is deployed? (Such as connect to database and create any tables that don't exist, and create threads that monitor some things) I cant find much about this online.

thanks!

[303 byte] By [JLina] at [2007-11-26 13:52:29]
# 1
Use a build tool like Ant. Netbeans probably supports it.
paulcwa at 2007-7-8 1:30:14 > top of Java-index,Java Essentials,Java Programming...
# 2
I am not sure what you mean, when you deploy a war file to tomcat on a webserver, ant does not get run does it?
JLina at 2007-7-8 1:30:14 > top of Java-index,Java Essentials,Java Programming...
# 3

Well I guess it depends on what you mean. You could set up your build tool to have jobs for creating the file for deployment, for copying it into place, and for doing things like setting up a database.

If you mean you want something on Tomcat that notices when there's a new war file, then runs some other script to init the database before using the new war file...then I have no idea.Maybe there's a hook into the Tomcat-side war file loading mechanism. I don't know.

paulcwa at 2007-7-8 1:30:14 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks for your replies, I don't think i am explaining clearly what I mean, I will make a different post with a more speciffic example.
JLina at 2007-7-8 1:30:14 > top of Java-index,Java Essentials,Java Programming...
# 5

I doubt it. And you probably don't want that tool anyway. Because you're going to deploy your application lots of times -- every time you make a change you're going to redeploy it. (Please don't tell me you chose JSP just because you can hot-deploy things.)

If you want to have things set up for the application, then set them up properly before you deploy it the first time. There's no reason why your application container (Tomcat or otherwise) should be involved in this process.

DrClapa at 2007-7-8 1:30:14 > top of Java-index,Java Essentials,Java Programming...