- 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
- Introduction
- Installation
- Junit
- Arrays
- Classes
- Data Types
- Expressions
- Interfaces
- JDBC
- Loops
- OOPS
- Serializable
- Strings
- Constructors
- Package
- Java Servlets
- Deployment
- Logging
- JSP
- ANT
- Web Services and Sockets
- Struts
- JPA
- Object Injection
- Annotations
- Reflection API
- Static Blocks
- Java Native Interface (JNI)
- Multithreading
- Tomcat Server
- Java Web Toolkit(JWT)
- Archive Files
- EJB(Enterprise Java Beans)
- JConsole
- Memory Profiling
- Hashing
- Exceptions
- Java Map Interface
- Java 8
- Garbage Collection
- Java 11
- Collections
Deployment
Subscribe to:
Posts (Atom)
-
What is the way to import only static members of a class? We can import using “import static packagename.classname.*” We can import using “i...
-
Q What is the difference between Array List and Linked List? Array List and Linked List both extend the List interface which extends Coll...
-
How do you detect a deadlock in a running Java program? We can use Jconsole to check for Deadlock which comes with JDK. There are also other...
No comments:
Post a Comment