Home TOC |
![]() ![]() ![]() |
Building and Deploying the Getting Started Application Using Ant
Now the example Web application is ready to build and deploy.
Setting the CLASSPATH
To build and run the example code, you will need to set the CLASSPATH variable properly. Instructions for setting up the CLASSPATH can be found online at
http://java.sun.com/j2se/1.4/docs/tooldocs/solaris/classpath.html
For this example, the CLASSPATH, which will need to include the <
JWSDP_HOME
>/webapps/gs/WEB-INF/classes
directory, is set in the build file described in the next section. Information on what directories need to be included in the CLASSPATH can be found at "Managing Files" in the JavaTutorial, which can be viewed from:
http://java.sun.com/docs/books/tutorial/java/interpack/managing- files.html
Creating the Build File for Ant
This release of the Java Web Services Developer Pack includes
ant
, a make tool that is portable across platforms. Documentation for theant
tool can be found in the fileindex.html
from the <JWDSP_HOME
>/docs/ant/
directory of your Java WSDP installation.To use
ant
for this example, create the filebuild.xml
in thegs/
directory. The code for this file follows:<!-- Setting up the Getting Started example to prepare to build and deploy --> <project name="wspack-getting-started-example" default="" basedir="."> <target name="init"> <tstamp/> </target> <!-- This section sets properties used in the rest of this build file --> <property name="build" value="build" /> <property environment="myenv" /> <!-- These libraries need to be included in the CLASSPATH --> <path id="classpath"> <fileset dir="${myenv.JWSDP_HOME}/common/lib"> <include name="*.jar"/> </fileset> </path> <!-- This section prepares the directory structure needed for Web applications --> <target name="prepare" depends="init" description="Create build directories."> <mkdir dir="${build}/WEB-INF/classes" /> </target> <!-- This section compiles the Java files and copies the HTML and JSP pages to the appropriate locations --> <target name="build" depends="prepare" description="Compile app Java files and copy HTML and JSP pages" > <javac srcdir="." destdir="${build}/WEB-INF/classes"> <include name="**/*.java" /> <classpath refid="classpath"/> </javac> <copy todir="${build}"> <fileset dir="."> <include name="*.html" /> <include name="*.jsp" /> </fileset> </copy> </target> <!-- This section deploys the application by copying the appropriate files to the webapps/ directory --> <target name="deploy" depends="build" description="Deploy app to webapps."> <copy todir="${myenv.JWSDP_HOME}/webapps/gs"> <fileset dir="${build}" /> </copy> </target> </project>Compiling the Source Files
Tomcat automatically compiles JSP pages. The steps for compiling the Java class (
Converter.java
) follows.
- In a terminal window, go to the
gs/
directory if you are creating the application on your own, or go to the <JWDSP_HOME
>/docs/tutorial/examples/gs/
directory if you are compiling the example files downloaded with the tutorial.- Type the following command to build the Java files:
ant buildThis command compiles the source files for the
Converter
class. It places the resulting class files in thegs/build/WEB-INF/classes/
directory as specified in the build target inbuild.xml
.Deploying the Application
A Web application is defined as a hierarchy of directories and files in a standard layout. In this example, the hierarchy is accessed in an "unpacked" form, where each directory and file exists in the file system separately. In later releases of the Java Web Services Developer Pack, this chapter will discuss creating a Web ARchive (WAR) file for deploying your application and handling security issues. This section includes information for deploying your application. For information on handling security issues in this release, read Security Manager How-To in <
JWDSP_HOME
>/docs/tomcat/security-manager-howto.html
.The
build.xml
file includes commands for deploying the Web application. The steps for deploying this Web application follow.
- In a terminal window, go to the
gs/
directory.- Type the following command to deploy the Web application files:
ant deployThis command copies the Web client file,
index.jsp
, to<
JWSDP_HOME
>/webapps/gs/
and copies the Java class file,Converter.class
, to<
JWSDP_HOME
>/webapps/gs/WEB-INF/classes/
.
Home TOC |
![]() ![]() ![]() |