TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
首先 ,在我们的工作目录(如我的是c:java)创建一个springapp的目录(你可以将这个目录建在任何地方),然后,在springapp目录下创建子目录src,用来保存java资源文件。 建立WEB-INF子目录,和它的classes,lib子目录。 把你应用中所需要的*.jar文件拷入lib目录。
OK,你的目录应该这个样子:
-spirngapp
-WEB-INF
-classes
-lib
-src
下面是ant的build.xml文件:
<?xml version="1.0" encoding="gb2312"?>
<project name="springapp" basedir="." default="usage">
<property file="build.properties"/>
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="docdir" value="doc"/>
<property name="build.dir" value="WEB-INF/classes"/>
<property name="name" value="springapp"/>
<path id="master-classpath">
<fileset dir="WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="/common/lib">
<include name="Servlet.jar"/>
</fileset>
</path>
<target name="usage">
<echo message=""/>
<echo message=" build file"/>
<echo message="-----------------------------------"/>
<echo message=""/>
<echo message="Available targets are:"/>
<echo message=""/>
<echo message="build --> 编译源文件"/>
<echo message="deploy --> 部署应用"/>
<echo message="deploywar --> 部署war文件"/>
<echo message="javadoc --> 创建文档"/>
<echo message=""/>
</target>
<!-- =========================================================== -->
<!-- spring tasks by yanger 2003-11 -->
<!-- =========================================================== -->
<target name="build" description="Compile main source tree java files">
<javac destdir="" >
<src path=""/>
<include name="**/*.java"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="deploy" depends="build" description="Deploy application">
<copy todir="/webapps/" >
<fileset dir="">
<include name="**/*.*"/>
</fileset>
</copy>
</target>
<!-- 将war文件放在父目录下,我的是c:java -->
<target name="deploywar" depends="build" description="Deploy application as a WAR file">
<war destfile="../.war" webxml="WEB-INF/web.xml">
<fileset dir="">
<include name="**/*.*"/>
</fileset>
</war>
<copy todir="" preservelastmodified="true">
<fileset dir="..">
<include name="*.war"/>
</fileset>
</copy>
</target>
<!-- =================================================================== -->
<!-- Javadoc -->
<!-- =================================================================== -->
<target name="javadoc" description="Creates API documentation (JavaDocs) ">
<delete dir="" failonerror="false"/>
<mkdir dir=""/>
<javadoc
destdir=""
access="private"
author="true"
version="true"
use="true">
<classpath refid="master-classpath"/>
<fileset dir="">
<include name="*.java"/>
</fileset>
</javadoc>
</target>
</project>
这个Ant脚本包含了建立应用主要的工具命令,但是,这个脚本要配合build.properties使用.
# Ant properties for building the springapp
#deploy.path=/home/trisberg/jakarta-tomcat-4.1.24/webapps
deploy.path=d:/Tomcat 5.5/webapps
#deploy.path=c:/bea/user_projects/domains/mydomain/applications
#tomcat.home=/home/trisberg/jakarta-tomcat-4.1.24
tomcat.home= d:/Tomcat 5.5
#tomcat.manager.url=http://localhost:8080/manager
#tomcat.manager.username=admin
#tomcat.manager.password=tomcat
现在我们运行build, deploywar命令,并启动tomcat,
这样我们就成功地建立了一个mvc应用,访问http://loaclhost:8080/springapp/hello.htm
源码下载:http://file.javaxxz.com/2014/10/1/045855422.zip |
|