Deployment

  • Ant
    • Ant is the Java version of the make utility that is commonly used to build programs written in C or C++.
    • A programmer writes ANT build scripts to perform repetitive tasks such as compiling and packaging compiled code into Archives.
  • Deployment Descriptor
    • Every Java application has a deployment descriptor that is located at WEB-INF/web.xml, relative to the root of the deployment folder.
    • So if the deployable objects are stored in folder "webapp", our deployment descriptor is located at webapp/WEB-INF/web.xml
    • The web.xml file configures information such as servlets and url-patterns that lead to their invocation.
  • To Deploy an application on web server we create a Directory Structure as follows.
    • Create a Project Directory Let us call it as demojdbc
      • All our Html and other view files rest in this directory
    • In the Project Directory we create a folder called as WEB-INF.
      • In WEB-INF we create a folder called as classes
        • In classes we copy the compiled classes
    • We will also create a file "web.xml" inside WEB-INF which will take care of our server mappings.
      • The basic structure of a "web.xml" file is as follows.
      •  <?xml version="1.0" encoding="UTF-8"?>  
         <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">  
          <display-name>demojdbc</display-name>  
          <servlet>  
              <servlet-name>formservlet</servlet-name>  
              <servlet-class>formservlet</servlet-class>  
          </servlet>  
          <servlet-mapping>  
              <servlet-name>formservlet</servlet-name>  
              <url-pattern>/formservlet</url-pattern>  
          </servlet-mapping>  
          <servlet>  
              <servlet-name>reportservlet</servlet-name>  
              <servlet-class>reportservlet</servlet-class>  
          </servlet>  
          <servlet-mapping>  
              <servlet-name>reportservlet</servlet-name>  
              <url-pattern>/reportservlet</url-pattern>  
          </servlet-mapping>  
         </web-app>  
        
    • Next we need to create a WAR file of this directory structure.
      • To create a war file make sure your Java path is set in System Path.
      • Next go to your project directory using command prompt/terminal and use the following command
        • jar -cvf demojdbc.war *
      • Copy the mysql connector jar file in Apache Tomcat lib folder.
      • In system classpath add mysql connector jar file as well as servlet-api.jar file.
        • servlet-api.jar file is also found in same location.
        • During execution tomcat looks for these files for servlet as well as mysql classes.
        • By defining class path the system already knows path to these classes and provides them to Tomcat.
      • Open apache server page in browser
        • generally this is localhost:8080
      • Click on Manager App
        • If this asks for password you will need to add user in role in tomcat conf directory tomcat-users.xml file with following values.
        • Now restart your apache server.
      • After clicking on Manager App undeploy any applications with same name.
      • Scroll down and you will see example to deploy war.

      • Deploy the war and you will be able to goto url
        • http://localhost:8080/demojdbc/form.html

    No comments:

    Post a Comment