日期:2014-05-18  浏览次数:20723 次

一个ant小问题,运行jar需要外部包,谢谢!
当需要用到外部包时,例如Oracle的classes12.jar等  
用:  
<?xml   version= "1.0 "   encoding= "UTF-8 "?>  
<project   name= "HelloAnt "   default= "dist "   basedir= ". ">  

<!--   set   global   properties   for   this   build   -->  
<property   name= "src "   value= ". "/>  
<property   name= "build "   value= "classes "/>  
<property   name= "distribute "   value= "dist "/>  
<property   name= "outFile "   value= "Testant "/>  
<property   name= "lib "   value= "./lib "/>  
<property   name= "mainClass.name "   value= "testa.TestAnt "/>  


<path   id= "lib.path ">  
<fileset   dir= "${lib} ">  
<include   name= "**/*.jar "/>  
</fileset>  
</path>  

<path   id= "project.classpath ">  
<pathelement   location= "${build} "/>  
</path>  

<target   name= "init ">  
<!--   Create   the   time   stamp   -->  
<tstamp/>  
<!--   Create   the   build   directory   structure   used   by   compile   -->  
<mkdir   dir= "${build} "/>  
</target>  

<target   name= "compile "   depends= "init ">  
<!--   Compile   the   java   code   from   ${src}   into   ${build}   -->  
<javac   srcdir= "${src} "   destdir= "${build} "   >  
<classpath   refid= "lib.path "/>  
</javac>  

</target>  

<target   name= "dist "   depends= "compile ">  
<!--   Create   the   distribution   directory   -->  
<mkdir   dir= "${distribute}/lib "/>  

<!--   Put   everything   in   ${build}   into   the   output   JAR   file   -->  
<!--   Add   a   timestamp   to   the   output   filename   as   well   -->  
<jar   jarfile= "${distribute}/lib/${outFile}-${DSTAMP}.jar "   basedir= "${build} ">  
<manifest>  
<attribute   name= "Main-Class "   value= "${mainClass.name} "/>  
</manifest>  
<fileset   dir= "${lib} ">  
<include   name= "**/*.jar "/>  
</fileset>  
</jar>  
</target>  

<target   name= "clean ">  
<!--   Delete   the   ${build}   and   ${distribute}   directory   trees   -->  
<delete   dir= "${build} "/>  
<delete   dir= "${distribute} "/>  
</ta