Posted by: Tharindu | April 24, 2010

Installing Tomcat, MySQL on Mac OS to run JDBC JSP or Servlet Applications with MySQL

I wanted to install tomcat, MySQL and then run a jsp application that connects to a MySQL DB on tomcat in Mac OS X. I have been using Mac OS for more than a year still only used it for mainly iPhone Development work. For other work on development I mostly used my Ubuntu OS at home PC. So I started all this from searching in google like ‘how to install tomcat on mac os’ and then ‘how to install mysql on mac os’ and then ‘how to set environment variables on mac os’ so and so whole day to run my app on tomcat at my MacBook. So I thought it would be useful to blog all these steps together for someone to finish this little easily. I will blog where you should refer for each step and after finishing you can come back here to see what next to do. ok great, lets just remind how i started. ha ha

1. Installing Tomcat – I have installed apache tomcat 6.0.24 exactly following same steps given in following article by Apple, eventhough it describes steps on installing 4.0.1 it is the same for later version of tomcat as well. It’s just a matter of downloading the tomcat distribution. You don’t need to complete the whole process. Just stop when you see tomcat up and running. I stopped my self at the end of ‘Starting and Stopping Tomcat’ section.

Java and Tomcat on Mac OS X

2. Install a text editor that can run from terminal (Optional). – Usually vi command is the preferred way of editing text files on Unix OSs. But for Mac OS X you should try with Text Wrangler. it has easy to install dmg file and after install Go to Menu TextWrangler -> InstallCommandLineTools… Now you can use ‘edit [filename]’ from command line to open up text files you want to edit instead of using vi. This looks much pleasant when you edit files.

3. Setting up Environment Variables – $CATALINA_HOME, $JAVA_HOME, $ANT_HOME. To setup environment variables create a file named ‘.profile’ in your home directory or edit it if it’s already there. Open it up with TextWrangler or use vi to edit it. Now add tomcat home, java home and ant home like below.

>edit .profile
[edit the file to set values and save]
>source .profile


CATALINA_HOME=/usr/local/apache-tomcat-6.0.24
export CATALINA_HOME;
JAVA_HOME=/Library/Java/Home
export JAVA_HOME;
ANT_HOME=/usr/share/ant
export ANT_HOME;

Important points here: Usually Mac OS comes with Java and default Java Home directory is located at /Library/Java/Home. In case you want to know where your ant home is. Type command ant -diagnostics then scroll up to see where ant.jar is in command line output. You know where ant is then.

4. Installing MySQL on OS X – This is pretty easy with Mac OSX Distribution you could download at MySQL web site. You can easily install MySQL with installer and then follow the instructions in Read Me to start MySQL server to work with.

Download Mac OS X MySQL Server Distribution

Important points here: Once you setup alliances in ~/.bash_profile as in README, To setup a root password use following command mysqladmin -u root password passwd

5. Setting up tomcat to connect to MySQL – you have to add the mysql-connector jar file to library folder and also edit the context.xml file in tomcat server. Read the detailed steps in following article to understand it fully.

MySQL DBCP Example on tomcat 6

Now you can run your JSP or Servlet application without any issues on Mac OS within tomcat server with MySQL databases.

Advertisements

Responses

  1. Thanks for sharing, I think I’ll be needing this in the future.

    Like

  2. Hi, just wanted to tell you, I loved this blog post.
    It was practical. Keep on posting!

    Like


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: