ant build里如何指定classpath

时间:2022-07-22
本文章向大家介绍ant build里如何指定classpath,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

我的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执行成功: