Friday 4 March 2016

Creating and Deploying Servlet without using Eclipse

This tutorial will guide you how to create and deploy Servlet without using Eclipse IDE.

Step 1. Download Tomcat : Tomcat is an application server from the Apache Software Foundation that executes Java servlets and renders Web pages that include Java Server Page coding.
Download latest release of Tomcat https://tomcat.apache.org/download-80.cgi
Step 2. Configure Tomcat : Unzip the tomcat package to C (or other) drive in my case it is D:\software\apache-tomcat-7.0.65-windows-x64\apache-tomcat-7.0.65

Now setup the JAVA_HOME, CATALINA_HOME, PATH environment variable:

Creating JAVA_HOME :
Click on -> Control Panel -> System -> Advanced->Environment Variable in User variables tab add new variable name:  JAVA_HOME and variable value :  C:\ "top level directory of your java install"
eg: variable name JAVA_HOME
      variable value :  C:\Program Files\Java\jdk1.8.0_40
      Note: Separate variable values by semicolon, if other value already exists(;)

Creating CATALINA_HOME :
Click on -> Control Panel -> System -> Advanced->Environment Variable in User variables tab add new variable name:  CATALINA_HOME and variable value :  C:\ "top level directory of your Tomcat install"
eg: variable name CATALINA_HOME :
      variable value :  D:\software\apache-tomcat-7.0.65-windows-x64\apache-tomcat-7.0.65
      Note: Separate variable values by semicolon, if other value already exists(;)

Appendng PATH :
Click on -> Control Panel -> System -> Advanced->Environment Variable in User variables tab select path variable and click on edit button. In variable value section give a semicolon and at the end paste the following text : %PATH%;%JAVA_HOME%\bin;%CATALINA_HOME%\bin

Step 3. Starting Tomcat: Go to the location of startup.bat D:\software\apache-tomcat-7.0.65-windows-x64\apache-tomcat-7.0.65\bin and double click on startup.bat
Now go to the browser and give url as localhost:8080 it should bring the apache tomcat home page.


Step 4. Creating Directory structure;
Step 5. Creating Servlet:

import javax.servlet.http.*;  
import javax.servlet.*;  
import java.io.*; 

public class DemoServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException{
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.println("<html><body>");
pw.println("Welcome to servlet");
pw.println("</body></html>");
pw.close();
}
}

Step 6. Compiling Servlet:
Go the directory containing DemoServlet and compile DemoServlet using servlet-api.jar.
eg: javac -classpath "D:\software\apache-tomcat-7.0.65-windows-x64\apache-tomcat-7.0.65\lib\servlet-api.jar" "DemoServlet.java"
Copy the DemoServlet.class file to the classes directory.

Step 7. Creating Deployment Descriptor:

<web-app>
  
<servlet>
     <welcome-file-list>
    <welcome-file>index.html</welcome-file>
   <welcome-file>default.html</welcome-file>
    </welcome-file-list>  
    <servlet-name>demo</servlet-name>  
    <servlet-class>DemoServlet</servlet-class>  
</servlet>  
  
<servlet-mapping>  
    <servlet-name>demo</servlet-name>  
    <url-pattern>/demoPage</url-pattern>  
</servlet-mapping>  
  
</web-app> 


Step 8. Deploying application to server:

Method 1-> Copy the application folder (here it is context root) to the apache tomcat's webapps directory for example I copied inside D:\software\apache-tomcat-7.0.65-windows-x64\apache-tomcat-7.0.65\webapps

Method 2->  Create WAR of your application and deploy it to tomcat through browser.
eg: Creating WAR, in cmd do  D:\myPrograms\servlets\web-app>jar -cvf myProject.war *
      Upload myProject.war and deploy in Tomcat server.

Step 9. Access the Servlet through URL: http://localhost:8084/myProject/demoPage



The caveman who didn't say anything to you

Today I watched  caveman "romantic film written and directed by Herschel Faber and starring Skyler Astin, Camilla Belle. I found myself in the character of Dean, one of the cavemen who had many things to say and finally said them all. But the difference between Dean and me was I did not say..

I did not say that..
I noticed your each and everything from very first day you entered to our zone..
I did not say that..
Your presence made me alive, I could finish my work before deadlines so that I'll find sometime to stay around you..
I did not say that..
Your every glimpse made me so  energetic I could happily survive in all the odd circumstances..
I did not say that..
My heart pounded out of my chest, every time, every time I saw you smiling ..
I did not say that..
I wanted to get down to the knee and tell you what I feel for you and assemble the courage to be the happiest man of the universe..
I did not say that..
I wanted to sing for you every morning when the sun rises..
I wanted to hold your hands tight in your good/bad times..
I wanted to drink with you as hard as possible..
I wanted to dance with you as no one is watching us..
I wanted to be a hardcore veggie for you..
I really wanted to be part of your .. !!!

I wish life could have been like the movie, a happy ending, where a caveman finds his true mate and becomes the most luckiest man for forever. I wish there wouldn't have been a wall of religion between us.  I wish I would have met you way back when you weren't with someone else ..

And last but not the least.. I will let you know that.. "You say it best, When You Say Nothing At All."

God Bless ya  bebe!!