Continuous Integration: Tomcat Setup
In this tutorial series we will explore a rarely discussed (but highly valuable) process of developing software that is disappointingly absent in the iOS and mobile world: Continuous Integration.
Also available in this series:
- Continuous Integration: Series Introduction
- Continuous Integration: Tomcat Setup
- Continuous Integration: Hudson Setup
- Continuous Integration: Scripting Xcode Builds
- Continuous Integration: Script Enhancements
Where We Left Off
In part 1 we introduced Continuous Integration as a way to improve the software development process and reduce the time we spend integrating code, building and signing our apps and distributing them for use.
Introducing Apache Tomcat
Apache Tomcat (or just Tomcat) is an open source web server that supports Java Servlet and JavaServer Pages. Tomcat is required because our CI software of choice (Hudson) is written in Java and needs a web server to run on. As you will soon find out, Tomcat is relatively easy to set up but configuring it for proper use can be a little tricky. We'll go through it step by step.
Step 1: Check System Requirements
Please check your system meets the following software requirements:
- OSX Snow Leopard or Higher
- Xcode 4.0 or higher
- Java 1.6 or higher
To check what version of Java you have installed, open a terminal window and enter:
If you have Snow Leopard installed, this should be fine. If you are running Lion, you might not have Java installed. If it needs to be installed go to http://support.apple.com/kb/DL1421 and follow the instructions install the latest version.
Step 2: Download Tomcat
Navigate to http://tomcat.apache.org/download-70.cgi and download the 'tar.gz' in the 'Core' section in Binary Distributions. Go to your downloads folder, unarchive the download and then rename the folder to something a bit more human readable. I'm going to call mine "tomcat".
Step 3: Install Tomcat
Tomcat can be placed anywhere on the OS X file system, however, it is best to place it in the '/usr/local' directory. We're going to do all this using the unix terminal, so open up a new terminal and navigate to your downloads directory using the 'cd' (change directory) command:
Next, move the tomcat directory to the /usr/local directory using the 'mv' command:
mv tomcat/ /usr/local
Tomcat is sitting in the
/usr/local directory and ready to be used! Before we can start it up though, we need to do a few things.
Step 4: Configure Tomcat
If we try and start up Tomcat now, we will run into a few ownership and permission errors. We need to tell the file system that you own that folder and have permission to use it.
First, navigate to the /usr/local directory:
Next, we need to make sure the owner of the tomcat folder (and all the sub files and folders) is us. To change the owner of something on unix, we use the 'chown' command:
sudo chown -R username tomcat
Making changes like permissions or file ownership requires administrative privileges. Typing "sudo" before the command tells terminal we are an administrator. If we can prove it by entering a valid password, then the command is executed.
We also need to make some scripts executable, so the server can do its thing:
sudo chmod +x tomcat/bin/*.sh
This makes all the files that end in '.sh' in tomcats bin folder executable.
Finally, before we start we need to increase the amount of virtual memory that tomcat can use. Its default amount is 64 mb and this is sometimes not enough, especially when we are working with large projects.
To do this, we need to edit a configuration file in the tomcat directory. Open a finder window and in the top menu navigate to "go->Connect to server". In the window that pops up, enter:
Find the "cataline.sh" file and open it in a text editor. If you are looking for a great and
free text editor, I recommend you checkout text-wrangler at http://www.barebones.com/products/textwrangler/) Around line 100 (below the #OS Specific support comment) add the following line:
export JAVA_OPTS="-Xms128m -Xmx512m"
This line sets two variables. Xms defines the memory that your tomcat server starts with. Xmx sets the maximum amount of memory that your server can use.
Step 5: Starting And Stopping Tomcat
We're ready to start Tomcat up! To start the server, we need to execute a startup script found in tomcat's bin folder. So, open a terminal and run the follow command:
If all goes well, you should see something like this in your terminal window:
Now, open a browser and enter the following into your browser bar:
Lo' and behold, we have a running instance of Tomcat!
If you ever need to stop tomcat (restarting after a config edit for instance), all you need to do is run this script from the terminal:
In the next article, we're going to install our CI server, "Hudson" and configure it to work with our svn or git project using either ssh or https authentication. We'll also have a dig inside the hudson directory to get an understanding of how it stores and works with the files. Catch you next time!