Sunday, October 5, 2008

Run Tomcat Server Under Apache Server

In this post I am trying to give you information of running tomcat server under apache server on LINUX. If you want to do so then follow these instructions:

  1. First of all get Apache HTTP server from apahce site http://httpd.apache.org and apache tomcat server from http://tomcat.apache.org
  2. Install both Apache and Tomcat servers on your system.
  3. Now get tomcat connector from http://tomcat.apache.org/download-connectors.cgi
  4. Now start extracting tomcat connectors file and installing it on bash shell:
  5. $gunzip tomcat-connecters-x.x.xx-src.tar.gz
  6. $tar -xvf tomcat-connecters-x.x.xx-src.tar
  7. $cd tomcat-connecters-x.x.xx-src/native
  8. $./configure --with-apxs=APACHE_PATH/bin/apxs
  9. $make (compiling the installation files)
  10. $make install (installing files)
  11. $cp apache 2.0/mod_jk.so APACHE_PATH/modules
  12. Now configuring Tomcat server:
  13. $vi TOMCAT_PATH/conf/server.xml
  14. In this file add
    <Listener classname="org.apache.jk.config.ApacheConfig" modJk="APACHE_PATH/modules/mod_jk.so"/ >
    in
    <engine name="Catalina" defaulthost="localhost">...<engine> block.
  15. Restart tomcat server if it is running: $./TOMCAT_PATH/bin/shutdown.sh then $./TOMCAT_PATH/bin/startup.sh
  16. Now doing Tomcat configuration
  17. $vi TOMCAT_PATH/cont/auto/mod_jk.conf
  18. Copy appropriate JkMount files from block to outside of it. eg JkMount /abc ajp13
  19. Now configuring Apache server
  20. Open apache configuration file $vi APACHE_PATH/conf/httpd.conf
  21. Add following line at the end of file: Include TOMCAT_PATH/conf/auto/mod_jk.conf
  22. Also add LoadModule jk_module modules/mod_jk.so in httpd.conf file.
  23. Restart Apache server: $/usr/sbin/apachectl restart
  24. And you have dont it!!!
Now you can run tomcat server applications with the layer of apache server such as if you are running http://localhost:8080/tomcat_project then now you can run it as http://localhost/tomcat_project you will get redirected to your project.

Reference:
http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html




Monday, September 22, 2008

Naming conventions for class, variables and functions

This post is related to the naming conventions of the identifiers that we are declaring in the program. During programming the problems that I have faced in programming and have learnt from others how to do declaration of class, function and variables. So for that I am published this post to reduce the problems that I have faced that you don't have to face it.

Class Declaration:
Always declare class name with first character in the Capital letter. ie class Increment. If the class name contains two words such as "vishal" and other as "joshi" then declare class as class VishalJoshi. Give some useful name to the class so that one can understand that this class is doing some particular work; such as if a class is related to person's information class then declare it as class PersonInformation.


Variable Declaration:
In variable decalration, don't try to give useless name such as int i. Give some useful name such as if a variable is for temparary use decalre it as int temporary;. Now in such a way if a variable is used for declaring storing name of a person then decalre it as String personName, here put first letter of first word in small letter and first letter of second word in the capital letter, so that it becomes easy for others to understand the decalration of variable. Don't put underscore (_) in the declaration till possible and useless name; and even though the name of variable becomes too long let it be long.

Function Declaration:
In function declaration, give function name as void createListing(); same as variable declaration. But give some useful name to the function so that one can get idea of what the function is doing, such as for generating new random password declare function as
public String generateRandomPassword(). Here one can understand that this function is used to generat a random password. Here also don't put underscore (_) in between the words this is bad habit.


From this post you might have got some idea of declaring variables, classes and functions in your code. Due to this declarations your code becomes easy to understand for you and others also and you also don't have to do a lot of documentation for your code. If you'll declare variables using useless words then you also will have to face a lot of problem. So please give some meaningful name to the variables, functions and classes.