I have a java application that up until now was run as a stand alone java application (i.e. executable jar). I now need to deploy it in Tomcat as a servlet. It doesn’t need to actually process any HTTP requests though, but it needs to be started using tomcat.
What are the steps required to convert the project so that it can be deployed in Tomcat? I’m using maven as a build tool and Java 1.5.
I understand that you want to run this app on server’s startup. The best way would be implementing
ServletContextListenerand run the app in thecontextInitialized()method. E.g.Register this in
web.xmlas follows:That’s it. No need to wrap it in flavor of a
HttpServletas you aren’t going to fire HTTP requests on it.You however need to ensure that it runs in its own thread, otherwise it would block the startup. If it doesn’t, then wrap it in a
Runnableand execute it usingExecutorService.