Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

servlet deployment

Status
Not open for further replies.

developerinlondon

Programmer
Jan 11, 2003
196
GB
anyone knows of a good source for tutorials for deploying servlets with multiple servlet files, packages etc?
i went through the oreilly ant manual but it speaks about how ant works and about a sample scenario (non-servlet) but not what steps in what sequence needs to be done if we were to do it without ant.
So far I am guessing the steps can be like following :
1) create a directory called 'build' and copy all of the source files onto this directory. (eg if I have package1.library1.java, package1.library2.java, package2.servlet1.java, package2.servlet2.java I would put hem all in the same directory(
2) javac -d . -classpath [put all the library files' locations one by one] xxx.java
where xxx.java is one of the above files.
Doing this for all of the above files will create directories package1 and package2 under the 'build' directory and put .class files in them.
3) if there is a log4j.properties file put this in the build directory also.
4) now create the following directory structure under build :
build
-- WEB-INF
-- -- web.xml
-- -- log4j.properties
-- -- classes
-- -- -- package1
-- -- -- -- library1.class
-- -- -- -- library2.class
-- -- -- package2
-- -- -- -- servlet1.class
-- -- -- -- servlet2.class

5) once this is created go to the 'build' directory and jar it using following -
jar cvf servlet1.war WEB-INF
this will create the war file in the 'build' directory.
6) Run Tomcat Manager and deploy the created war file to it.
7) Check and see if it works.
8) IF not or I need to change a line in my code then do all the above steps again!

Am I on the right track here? is it a standard to use ANT since its such a long process? Is there any sample ANT build.xml I can get anywhere that does something similar to the above?

thanks
 
This would be wrong :

jar cvf servlet1.war WEB-INF

You should :

jar cvf servlet1.war *

Yes, this is basically how you would do it.
How you do it exactly is up to you - whatever makes most sense to you.
However I would not actually copy the source files into the build directory - I would just compile them from your source directory into build.

Whether you use ant or not is again up to you - but yes, a lot of software developers do use it because it is simple (once set up).

One thing I would say, is that you should create a .jar file of your classes and add that to WEB-INF/lib rather than your classes in WEB-INF/classes.

Not sure if there are "example" ant scripts around - have you googled ?!

Here is an example of one we use. Don't expect it to work straight off for you, but it will give you an idea.

Code:
<?xml version="1.0"?>
    
<project name="MyWebApp" default="makerun" basedir=".">

  <property name="common.lib"      value="../common/code/lib"/>
  <property name="common"          value="../common/lib"/>
  <property name="apps"            value="../apps/code/lib-ext"/>
  
  <property name="build.home"      value="build"/>                         <!-- Build directory               -->
  <property name="deploy.home"     value="web"/>                        <!-- Source html & jsp             -->
  <property name="tools.home"      value="tools"/>                         <!-- Tools directory for install scripts etc. -->
  <property name="lib.home"        value="code/src"/>                      <!-- Source classes                -->
  <property name="lib.class"       value="code/class"/>                    <!-- Compiled class output         -->
  <property name="build.tomcat"    value="${build.home}/tomcat/"/>         <!-- Dynamic output directory name -->
  <property name="release.home"    value="release"/>                       <!-- Release directory name        -->
  <property name="project.name"    value="MyWebApp"/>                     <!-- Name of the project           -->
  <property name="project.version" value="0.0.1"/>                         <!-- Version of the project        -->

  <!-- All static file extensions in one handy property -->
  <property name="staticfiles"    value="**/*.html,**/*.css,**/*.js,**/*.gif,**/*.png,**/*.jpg,**/*.jpeg,**/*.pdf"/>

  <!-- Compilation Classpath -->
  <path id="compile.classpath">
   <pathelement location="C:/java/iText.jar"/>
    <pathelement location="${common.lib}/AntTask.jar"/>
    <fileset dir="${common}">
      <include name="*.jar" />
    </fileset>
    <fileset dir="${apps}">
      <include name="*.jar" />
    </fileset>
  </path>

  <property name="compile.debug"       value="true"/>
  <property name="compile.deprecation" value="true"/>
  <property name="compile.optimize"    value="true"/>

  <target name="all" depends="clean,makerun"/>
  
  <target name="clean" >
    <mkdir dir="${build.home}"/>
    <mkdir dir="${release.home}"/>
    <delete>
      <fileset dir="${build.home}" includes="**/*"/>
    </delete>
  </target>

  <target name="init">
    <mkdir dir="${build.home}"/>
    <mkdir dir="${release.home}"/>
    <delete>
      <fileset dir="${release.home}" includes="**/*.*"/>
      <fileset dir="${build.home}" includes="MyWebApp.war"/>
    </delete>
  </target>

  <target name="dynamic" depends="init">
    <copy todir="${build.tomcat}">
      <fileset dir="${deploy.home}" includes="**/*.*"/>
    </copy>
  </target>

  <target name="lib" depends="dynamic">
    <mkdir dir="${lib.class}"/>
    <javac srcdir="code" destdir="${lib.class}" debug="true">
      <classpath refid="compile.classpath" />    
    </javac>
    <mkdir dir="${build.lib}"/>
    <jar basedir="${lib.class}" destfile="${build.tomcat}/WEB-INF/lib/MyWebApp.jar" />
  </target>

  <target name="makewar" depends="lib">
    <jar basedir="${build.tomcat}" destfile="${build.home}/MyWebApp.war" />
    <!--
    <delete includeemptydirs="true">
      <fileset dir="${build.tomcat}" includes="**/*"/>
    </delete>
    -->
  </target>
  
  <target name="makerun" depends="makewar">
    <echo message=""/>
    <fixcrlf destdir="${build.home}/" srcdir="${tools.home}" includes="install.sh" eol="lf" eof="remove"/>
    <taskdef name="makeself" classname="uk.co.landmarkinfo.ant.Makeself" classpath="${common.lib}/AntTask.jar"/>
    <makeself dest="${release.home}/MyWebApp.run" src="build" script="sh" scriptargs="build/install.sh" />
  </target>
  

<target name="javadoc"
	description="Create Javadoc API documentation">

	<mkdir dir="docs/javadoc"/>
	<javadoc sourcepath="code/src/"
		destdir="docs/javadoc"
		packagenames="*">
		<classpath refid="compile.classpath"/>
	</javadoc>	
</target>
  
  
</project>

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top