ITeye博客

ant学习笔记(六)

zzkathy · 2008-01-09 15:32 · Markdown

今天写了一段ant脚本,是用来编译,打包,运行java的。具体如下:

 <target name="compile">
  <javac srcdir="${src}"
             destdir="${bin}"
             source="1.4"
       encoding="UTF-8"
       deprecation="on"
       failonerror="true"
    >
   <classpath>
       <fileset dir="${lib}">
         <include name="*.jar"/>
       </fileset>
   </classpath>       
  </javac>
 </target>
 
 <target name="makejar" depends="compile">
  <jar destfile="${jar}/${jar.name}" basedir="${bin}">
   <manifest>
    <attribute name="Main-Class" value="${main.class}"/>
   </manifest>
  </jar>
 </target>
 
 <target name="run" depends="makedbjar">
  <java classname="${main.class}"
   fork="true"
   failonerror="yes"
   >
   <classpath>
    <pathelement location="${jar}/${jar.name}"/>
    <fileset dir="${lib}">
      <include name="*.jar"/>
    </fileset>
   </classpath>
  </java>
 </target>

大家注意其中的红色部分,喵喵一开始写的时候是jar="${jar}/${jar.name}" ,然后就一直出错。查阅了ant文档之后才发现其中有一句:When using the jar attribute, all classpath settings are ignored according to Sun's specification. 顿时汗如雨下,作了如上更改后终于得以成功-_-b

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。