classpath元素classpath就是指定我们运行java的时候所需要的类.比如jar包之类的 注意,classpath的指定可以是文件,或者是某个文件夹
<classpath>可以内嵌 <pathelement>、<path>、<fileset>、<filelist>、<dirset>等元素
1.pathelement
pathelement元素的path属性指向的不是一个预先定义的<path>,而是一个符合classpath规则的property
例如:
<property name="project.jar.path" value="D:/temp/temp.jar;D:/temp/temp1.jar" />
<classpath id="test">
<pathelement path="${project.jar.path}" />
</classpath>
<!--正确使用-->
错误使用:
误认为path应该指向一个预先定义的path是不正确的
<path id="classpath">
<fileset dir="${project.lib.path}">
<include name="**/*.jar" />
</fileset>
</path>
<classpath id="testclass">
<!--此处使用错误-->
<pathelement path="${classpath}" />
<!--正确使用-->
<pathelement refid="classpath" />
</classpath>
refid="classpath"不适没有${classpath}
location指定的是一个jar文件或者一个目录,与path区别为location可以去当前路径,当然可以使用绝对路径
<property name="project.jar.path" value="D:/temp/temp.jar;D:/temp/temp1.jar" />
<classpath>
<pathelement path="${project.jar.path}" />
<pathelement location="lib/helper.jar"/>
</classpath>
2.fileset
是一个文件夹,可以采用匹配模式来引入,这个适合在同一个文件夹下,文件名字比较多的情况下
<classpath>
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</classpath>
3.filelist
是一个文件集合适合引入不同路径的jar包,但是需要输入每个jar包的名字,比较繁琐,适合于jar包属于不同位置,比较分散但是不多的情况
<filelist id="third-party_jars" dir="${basedir}" files="foo.jar, bar.jar"/>
<classpath>
<filelist refid="third-party_jars" />
</classpath>
4.dirset
<classpath>
<dirset dir="${build.dir}">
<include name="apps/**/classes" />
<exclude name="apps/**/*Test*" />
</dirset>
</classpath>