rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » Java综合

ant小用(2009-09-29 16:54:19)

  ant实在是很强大,新手时一直不理解其强大之处,昨日偶编一脚本,寥寥数语,却妙用无穷。

  其中不乏CVS, SCP等操作。需要指出的有两点,一是SCP需要jsch的jar包,二是ant在编译时有可能出现编译未完成便莫名其妙的异常终止了。遇到这种情况,可能是中文问题惹的祸,网上查到两个解决方法,我两个都用了,添加两个方法,完全搞定。

eclipse->Run->External tool->External tool Configurations->Main->Arguments: -log org.apache.tools.ant.NoBannerLogger

eclipse->Run->External tool->External tool Configurations->JRE->VM arguments: -Duser.language=en

 <path id="compile.classpath">
  <fileset dir="${lib.dir}" includes="*.jar" />
  <fileset dir="${exclude-lib}" includes="*.jar" />
 </path>

 <!-- Initializing -->
 <target name="init">
  <delete>
   <fileset dir="${dest.dir}" includes="**/*" />
  </delete>   <mkdir dir="${dest.dir}" />
  <mkdir dir="${bak.dir}" />

  <tstamp>
   <format property="today" pattern="yyyy-MM-dd hh:mm:ss" />
  </tstamp>
  <echo message="${today}" />
 </target>

 <target name="prepare" depends="init">
  <cvspass cvsroot="${cvsroot}" password="${cvs.password}"
   passfile="ant-cvs.cvspass" />
 </target>

 <target name="external-check-out" depends="prepare">
  <cvs cvsRoot="${cvsroot}" package="${external.module.name}"
   dest="${external.dir}" passfile="ant-cvs.cvspass" />
 </target>

 <target name="check-out">
  <antcall target="external-check-out" />
 </target>

 <target name="compile" depends="check-out" description="Compile Java code">
  <mkdir dir="${build.dir}" />
  <echo message="+=============================================+" />
  <echo message="|     Start Building NGP for compilation      |" />
  <echo message="+=============================================+" />
  <javac srcdir="${src.dir}" destdir="${build.dir}" debug="${debug}"
   optimize="${optimize}" source="1.5" target="1.5" classpathref="compile.classpath">
  </javac>
  <echo message="+=============================================+" />
  <echo message="|      End Building NGP for compilation       |" />
  <echo message="+=============================================+" />
  <copy todir="${build.dir}">
   <fileset dir="${src.dir}">
    <exclude name="org/**"/>
    <exclude name="com/**"/>
   </fileset>
   <!--<fileset dir="${src.dir}" />-->
  </copy>
 </target>

 <target name="package" depends="compile">
  <echo message="+=============================================+" />
  <echo message="|     Start packageing NGP                    |" />
  <echo message="+=============================================+" />
  <war destfile="${dest.dir}/${project.name}.war" webxml="${web.dir}/WEB-INF/web.xml">
   <fileset dir="${web.dir}" />
  </war>
  <echo message="+=============================================+" />
  <echo message="|      End packageing NGP                     |" />
  <echo message="+=============================================+" />
 </target>

 <target name="bak" depends="package">
  <copy file="${dest.dir}/${project.name}.war" tofile="${bak.dir}/${project.name}.war" />
 </target>

 <target name="deploy" depends="bak">
  <echo message="+=============================================+" />
  <echo message="|     Start deploy NGP                        |" />
  <echo message="+=============================================+" />
  <scp trust="true" file="${dest.dir}/${project.name}.war" todir="${scp.connection}" />
  <echo message="+=============================================+" />
  <echo message="|      End deploy NGP                         |" />
  <echo message="+=============================================+" />
 </target>

顶一下
(0)
踩一下
(0)