Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Building Web Application With Ant and Deploying on Jboss 3.0

Building Web Application With Ant and Deploying on Jboss 3.0 Building Web Application With Ant and Deploying on Jboss 3.0 Previous Tutorial Index Next In this lesson I will show you how to build you web application and install on the Jboss 3.0

Tutorial Details:

application server.
After the completion of the lesson you will be able to include jsp, html and servlets in the ear file and deploy on the Jboss 3.0 application server. This example will provide a strong foundation for the further development. Ant script developed in this lesson will be used in subsequent tutorial for the development and deployment of complex J2EE Applications with little or no more modification.
In this lesson we will write one Hello World Servlet and a JSP file file to call Hello World Servlet. In order to deploy components we have to build .ear file which is the standard format for the deployment of J2EE application.
First of all let's understand the structure of .ear and .war files.
Enterprise Archive Contents
Enterprise Archive (.ear) component follows the standard directory structure defined in the J2EE specification.
Directory Structure of .ear archive
/
.war and .jar files
Meta-inf
application.xml
In the .ear file .war,.jar and application.xml file are packaged in the above format.
Enterprise Archive Contents
Web component follows the standard directory structure defined in the J2EE specification.
Directory Structure of Web Component
/
index.htm, JSP, Images etc..
Web-inf
web.xml
classes
servlet classes
lib
jar files
Root directory of the web archive ('.war' file) contains all the html, jsp, images files and the additional directories containing these files. In the root directory there is a special directory 'Web-inf' which contains the web deployment descriptor (web.xml), classes and the lib directory.
Directory Structure of Example2 directory
After understanding the structure of .ear and .war file let's look at the directory structure of example2 directory where we have work to develop the deployable .ear file.
Directory structure:
Description of Directory and its content:
Directory
Description
example2
Base directory which contains build.xml and the .ear file generated by Ant utility will be placed here.
build
Various files generated by Ant utility will be placed in different directories under this directory.
build/deploymentdesciptors
Web.xml and application.xml files are placed in this directory.
build/ear
Intermediate files for the assembling of example2.ear ear file are placed here.
build/jar
Any jar file if required will be placed in this directory.
build/war
Intermediate files for the assembling of example2.war ear file are placed here.
build/src
All the compiled .class files are placed in this directory.
src
All the java source files are placed here.
web
All the html,jsp, images etc. files are placed in this directory.
In this lesson we creating HelloWorld.java and index.jsp which is in the /src and /web directory respectively.
Source code of HelloWorld.java:
/*
* HelloWorld.java
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* The Hello World Servelet.
*
* @author Deepak Kumar
* http://www.roseindia.net
* deepak@roseindia.net
*/
public class HelloWorld extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("Hello World Servlet!");
out.println("");
out.println("");
out.println("

Hello World!

");
out.println("

Go to Home

");
out.println("");
out.println("");
}
}
Here is the code of index.jsp file:
<%@page language="java" %>


Welcome to Jboss 3.0 tutorial


Welcome to

Jboss 3.0 Tutorial


Congralutations you have successfully
installed lesson 2 tutorial


Click here
to
execute Hello World Servlet.


 


For more tutorials and examples visit
http://www.rosindia.net


 


Copyright © 2001 roseindia.net. All
rights reserved.




You can download all the file of this tutorial from here .
Writing Application and Web deployment descriptor
Since in this lesson we are developing one servlet and one jsp files so our deployment descriptor is very simple.
web.xml file:

PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">


HelloWorld
HelloWorld


/servlet/HelloWorld
HelloWorld


application.xml file:


Example 2


example2.war
/example2



Above application.xml file describe the content of example2.ear. Tag example2.war describe the name of web module (i.e.. example2.war) packaged in the archive. The context root of this example2.ear is eample2 .
Writing Ant build xml file
To build example2.ear file, I have written build.xml which compiles source code and builds deployable archive file.
build.xml file:






















































Above build.xml file is design to create example2.ear for us in the base directory.
Running Ant utility to build example2.ear
Now it's time to build example2.ear and deploy on the Jboss 3.0 application server.
To execute Ant utility go to c:\anttest\example2 directory and issue ant command.
Out put of ant command:
C:\anttest\example2>ant
Buildfile: build.xml
init:
[mkdir] Created dir: C:\anttest\example2\build\war\WEB-INF
[mkdir] Created dir: C:\anttest\example2\build\war\WEB-INF\classes
[mkdir] Created dir: C:\anttest\example2\build\ear\META-INF
build:
[javac] Compiling 1 source file to C:\anttest\example2\build\src
buildWar:
[copy] Copying 1 file to C:\anttest\example2\build\war\WEB-INF\classes
[copy] Copying 1 file to C:\anttest\example2\build\war\WEB-INF
[copy] Copying 1 file to C:\anttest\example2\build\war
[jar] Building jar: C:\anttest\example2\build\ear\example2.war
buildEar:
[copy] Copying 1 file to C:\anttest\example2\build\ear\META-INF
[jar] Building jar: C:\anttest\example2\example2.ear
all:
BUILD SUCCESSFUL
Total time: 8 seconds
C:\anttest\example2>|
The above process will create example2.ear in c:\anttest\example2 directory.
Deploying and testing J2EE application
Statrt Jboss 3.0 and copy example2.ear file into the JBOSS_HOME/server/default/deploy directory. Jboss application server automatically deploys the application. Open web browse and type http://localhost:8080/example2 in the web browser. Browse should show the screen something like this:
Also try to execute Hello World Servlet by clicking "Click Here to" link on the index.jsp in the browser.
In this lesson you learned how to write build.xml file to automate the process of .ear file creation. Ant utility with help of our build.xml file automatically compiles source code and assembles J2EE application for us. Ant utility is very power full and it reduces the development time significantly.
Previous Tutorial Index Next


 

Rate Tutorial:
http://www.roseindia.net/jboss/buildingwebapplicationwithant.shtml

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Building Web Application With Ant and Deploying on Jboss 3.0

View Tutorial:
Building Web Application With Ant and Deploying on Jboss 3.0

Related Tutorials:

The art of EJB deployment - JavaWorld August 2001
The art of EJB deployment - JavaWorld August 2001
 
Finalists announced for JavaWorld Editors' Choice Awards
Finalists announced for JavaWorld Editors' Choice Awards
 
Rumble in the jungle: J2EE versus .Net, Part 1
Rumble in the jungle: J2EE versus .Net, Part 1
 
Rumble in the jungle: J2EE versus .Net, Part 2
Rumble in the jungle: J2EE versus .Net, Part 2
 
Maven ties together tools for better code management
Maven ties together tools for better code management
 
Axis-orizing objects for SOAP
Axis-orizing objects for SOAP
 
Java tools reign supreme - JavaWorld celebrates the leading Java tools
Java tools reign supreme - JavaWorld celebrates the leading Java tools
 
Top 15 Ant Best Practices
Top 15 Ant Best Practices Ant, building and deploying Java applications required a hodgepodge of platform-specific scripts, makefiles, proprietary IDEs, or manual processes. Now, nearly every open source Java project uses Ant. A great number of companie
 
Clustering and Load Balancing in Tomcat 5, Part 1
The latest version of the Tomcat servlet container provides clustering and load balancing capabilities that are essential for deploying scalable and robust web applications.
 
Flexible User and Environment Ant Configuration
Flexible User and Environment Ant Configuration The de facto standard for building, packaging, and deploying Java applications is Apache Ant. Small differences in developers\' environments or preferences may cause problems with some Ant tasks that invo
 
Turn EJB components into Web services
Summary Web services have become the de facto standard for communication among applications. J2EE 1.4 allows stateless Enterprise JavaBeans (EJB) components to be exposed as Web services via a JAX-RPC (Java API for XML Remote Procedure Call) endpoint, al
 
ServerEclipse - Web Eclipse Plug-in
ServerEclipse - Web Eclipse Plug-in
 
Build scripts with Groovy and Ant
Build scripts with Groovy and Ant Summary In nearly all developers' toolboxes, Ant is the standard build tool for Java applications, thanks to its open, standard, and multiplatform structure. Though it represents a great improvement in automating produc
 
Building Web Application With Ant and Deploying on Jboss 3.0
This lesson shows you how to build you web application and install on the Jboss 3.0 application server. After the completion of this lesson you will be able to compile, assemble and deploy your J2EE application on Jboss 3.0 application server
 
10 Minutes Guide to Ant
10 Minutes Guide to Ant 10 Minutes Guide to Ant Previous Tutorial Index Next Introduction Well for the next 10 minutes get ready to devote to the ant guide. This will make some sence to the ant. Ant is a free tool under GNU Licence and is
 
Building Web Application With Ant and Deploying on Jboss 3.0
Building Web Application With Ant and Deploying on Jboss 3.0 Building Web Application With Ant and Deploying on Jboss 3.0 Previous Tutorial Index Next In this lesson I will show you how to build you web application and install on the Jboss 3.0
 
developing a Session Bean and a Servlet and deploy the web application on JBoss 3.0
developing a Session Bean and a Servlet and deploy the web application on JBoss 3.0 Writing Calculator Session Bean and Calling through JSP Previous Tutorial Index Next In this lesson I will show you how to develop a Calculator Stateless Session
 
Welcome to the Jboss 3.0 Tutorial
Welcome to the Jboss 3.0 Tutorial Welcome to the Jboss 3.0 Tutorial 10 Minutes Guide to Ant Comprehensive description of Ant with example. Building Web Application With Ant and Deploying on Jboss 3.0 This lesson shows you how to build you web
 
developing a Session Bean and a Servlet and deploy the web application on JBoss 3.0
developing a Session Bean and a Servlet and deploy the web application on JBoss 3.0 Writing Stateless Session Bean and Calling through Servlet Previous Tutorial Index Next In this lesson I will show you how to develop a Stateless Session Bean and
 
Struts Guide
Struts Guide Struts Guide This tutorial is extensive guide to the Struts Framework. In this tutorial you will learn how to develop robust application using Jakarta Struts Framework. This tutorial assumes that the reader is familiar with the web
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.