This is the sequel to my previous blog, regarding a Java/Ubuntu/JBoss/MySQL stack. There are various reasons to choose one or the other application server. Typically, tomcat (version 5/6) is the lighter weight servlet container and not technically and application server (no EJB’s, MDB’s, out of the box high availability, etc). While JBoss is a full J2EE implementation and a true application server. Resource requirements for tomcat is also smaller than JBoss. Infact, tomcat’s resource requirements are so low, I can’t easily find what they are. I remember using it on single core, P4′s with 512 megs of RAM and still had enough left over for a small IDE.
Another cool thing about a Java/Ubuntu/Tomcat/MySQL stack is that you can install all of it (including Eclipse, if you wanted) with a single command line. This is the foundation of this blog. The PHP world has the LAMP stack (with phpMyAdmin and BlueFish IDE) which can be installed, configured and up and running in half an hour. Now, us Java folks have the same.
Background:
My favorite configuration for this stack is the free-as-in-speech strategy. Normally, I like to use Sun’s JDK, but since Tomcat is free-as-in-speech, as well as MySQL, why not follow suit?
Ingredients:
- Dual core processor, I like AMD’s but Intels work just as well
- 512 MB RAM, but 1 Gig is better, especially with mysql installed on the same box
- Ubuntu Server Edition, 9.04 Jaunty
- Total time: 30 min
Installation:
In the command line, type:
- sudo apt-get install openjdk-6-jdk openjdk-6-jre tomcat6 tomcat6-admin tomcat6-common mysql-server-5.0 mysql-client-5.0
My internet connection is relatively quick, so this took about 5 min to download and about 5 min to install.
Verification:
- VERIFY MYSQL: Your mysql installation will ask you for a password for root. Provide one and remember it.
- VERIFY JAVA: In the command line, type java -version or javac -version, you should get a message that tells you which jdk you are using (openJDK) and which version (1.6)
- VERIFY TOMCAT: pull up the browser, and type: http://whatever_the_host_is:8080 You should get a “It works!” screen followed by location of your tomcat docs, examples and admin, if you haven’t installed them already.
The verification process should take about 5-10 minutes, provided everything goes well. If the above did not work, then you did something wrong.
Configure mysql:
You’ll want to allow your client machines to access your mysql database. Type the following:
- mysql -u root -p
- then type your root password you provided above, then type:
- GRANT ALL PRIVILEGES ON *.* TO ‘your_username’@’*’ IDENTIFIED BY ‘whatever_your_password_is’ with grant option;
The GRANT command will allow your clients to access the database. If you do not do this, then you can only access the database locally or at the local host. This took me about 5 mins.
Tomcat Notes:
- RESTART TOMCAT: sudo /etc/init.d/tomcat6 restart
/var/lib/tomcat6/webapps/ROOT/index.html is the default tomcat homepage
There you have it. Now you can write JSP’s and Servlets. Unfortunately, doing so it out of scope. Stay tuned for Hello World JSP and Servlet tutorials. Meanwhile, read up on the apache tomcat and sun tutorials.
References:
Side Notes:
You’ll probably want an IDE. The best free-as-in-speech IDE is Eclipse. You can install it via apt or synaptic, but it may not include extensions for J2EE (min JSP’s and Servlets). Download it here.