日期:2014-05-20  浏览次数:20653 次

ant调试的一个小问题,希望高手能帮忙解决下!
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<project   default= "dist "   name= "project   argon ">
<description> A   simple   java   project </description>
<property   name= "srcDir "   location= "src "   />
<property   name= "buildDir "   location= "build "   />
<property   name= "distDir "   location= "dist "   />

<target   name= "init ">
<tstamp>
</tstamp>
<mkdir   dir= "${buildDir} "   />
<mkdir   dir= "${distDir} "   />
</target>

<target   name= "complie "   depends= "init ">
<javac   srcdir= "${srcDir} "   destdir= "${buildDir} "   />
</target>

<target   name= "dist "   depends= "complie ">
<jar   destfile= "${distDir}/package-${DSTAMP}.jar "   basedir= "${buildDir} ">
<manifest>
<attribute   name= "Built-By "   value= "${user.name} "   />
<attribute   name= "Main-Class "   value= "package.Main "   />
</manifest>
</jar>
<jar   destfile= "${distDir}/package-src-${DSTAMP}.jar "   basedir= "${srcDir} "> </jar>
</target>

<target   name= "clean ">
<delete   dir= "${buildDir} ">
</delete>
<delete   dir= "${distDir} "   />
</target>

</project>

调试后出现:
Buildfile:   D:\workspace\hello\build.xml
init:
complie:
        [javac]   Compiling   2   source   files   to   D:\workspace\hello\build

BUILD   FAILED
D:\workspace\hello\build.xml:16:   Unable   to   find   a   javac   compiler;
com.sun.tools.javac.Main   is   not   on   the   classpath.
Perhaps   JAVA_HOME   does   not   point   to   the   JDK

Total   time:   750   milliseconds


我估计要添加一个classpath程序,但不知道怎么添加,希望高手能指导的详细点!谢谢!

------解决方案--------------------
在第一个 target 前加上,类库假设放在 ${lib} 下。

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

编译改为:

<target name= "complie " depends= "init ">
   <javac srcdir= "${srcDir} " destdir= "${buildDir} " />
      <include name= "**/*.java "/>
      <classpath refid= "classpath "/>
   </javac>
</target>

打包改为

<target name= "jar " depends= "complie ">
   <jar destfile= "${distDir}/package-${DSTAMP}.jar " basedir= "${buildDir} ">
     <fileset dir= "${classes} "/>
     <manifest>
       <attribute name= "Built-By " value= "${user.name} " />
       <attribute name= "Main-Class " value= "package.Main " />