I have an application which starts with Java Swings but in the execution flow of the application it makes use of Java servlets and JSPs. So I need to check whether a system on which this application will be running has Tomcat installed on it or not, therefore i can prompt the user to get it installed before hand.
I think there's no general solution to find out if a specific application is installed on a system if the application in question doesn't help by setting any hint or flag which signals that it already IS installed. It's even worse to find a solution which works not only for Windows but also for Linux or OS X.
In particular to install Tomcat you don't even have to run a real installation procedure. It would be enough to simply unzip a prepared archive and the system won't even notice that there is a user specific but still valid installation of Tomcat.
One idea which comes to mind is to check whether there's an environment variable called CATALINA_HOME which should usually be set on any system with a correctly set up Tomcat installation. And in case there's no such environment variable you could ask the user to choose a directory for a valid Tomcat installation and check if its contents really seem to be a Tomcat installation. I don't know what would be the best way to verify this without checking the existence of all Tomcat related files though.
Thanks for your reply but i was wondering then how some installers which need Tomcat as prerequisite finds the Tomcat with instalation. eg. while configuring eclipse for Tomcat or while installing any java based application it prompts for selecting the version of Java to be used. (Versions which aer already installed on the system).
I think there is something which installers do to check this. Please correct me if I'm wrong.
typical installers do definitely check for installed software but I'm pretty sure this means crawling typical directories for traces of the wanted piece of software. If you install Java or Tomcat on Windows it will TYPICALLY end up somewhere in the folder "program files" but you can't prevent a user to choose another non-typical location or use a simply ZIP file without an installer, as I already said.
It's even worse for UNIX/Linux systems because here it may vary from distribution to distribution where some specific applications are installed. So you will inevitably have to check all the different potential locations. This means you should at least have some fallback method if the automatic search mechanism fails.
Besides I guess the best way would be to check out some opensource installers you can use for your own application which are already made for these kind of problems! Reinventing this will be quite cumbersome. Unfortunately I don't have enough experience with these installer projects so you will have to compare their features on you own...