我的jsp项目里使用到了tomcat安装目录的lib文件夹下的jar包,因此在ant build时,需要将tomcat/lib也引入classpath:
build.xml源代码如下:
<?xml version="1.0"?>
<project name="jerryjsp" basedir="." default="build">
<property name="src.dir" value="src"/>
<property name="web.dir" value="WebContent"/>
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="jerryjsp"/>
<path id="master-classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="C:/MyApp/apache-tomcat-9.0.29/lib">
<include name="*.jar"/>
</fileset>
<pathelement path="${build.dir}"/>
</path>
<target name="build" description="Compile source tree java files">
<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.8" target="1.8">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
</target>
<target name="clean" description="Clean output directories">
<delete>
<fileset dir="${build.dir}">
<include name="**/*.class"/>
</fileset>
</delete>
</target>
</project>
使用path标签定义一个id为master-classpath的路径:
在ant target里,使用javac标签页执行编译,使用classpath标签页引入上述path标签指定的classpath:
ant build执行成功: