项目中应用ant

    项目中使用java+corba+c++,编译步骤繁多,首先要将idl文件编译成为java类,然后将java编译为class,再使用项目中的工具将idl编译成的java类,同步为bo文件和相应的boBean,才能使用。中间还牵扯到要将编译的文件copy来copy去。一直想摆脱jBuilder的束缚,无奈一直依赖于jBuilder编译idl文件。新项目仍然要使用同样的框架,趁着有空,引入了ant。

   中间遇到了点困难,卡住了很久。jbuilder编译idl时,可以一次编译很多idl文件。安道理jBuilder应该也是调用idl2java才对,我想当然的在调用idl时使用*.idl时,总是会出错,而且经常看到编译出的idl文件出现丢字符的情况。因为在jBuilder中也出现过同样的问题,换了VisiBroker自带的jdk,才能通过。所有我一直以为是jdk的问题,来回换了N多版本的jdk 仍然解决不到。直到后来,才发现使用idl2java,idl文件的先后顺序非常有关系,被依赖的一定要放在前面。idl2java才能成功。

   扫除了idl2jav这只拦路虎,发现调用vbjc编译idl2java生成的java也有问题,因为项目层次的关系,无法一次编译java文件。不过我猜测vbjc同样应该是调用javac才对,只是classpath加入了VisiBroker的jar而已。找到VisiBroker下bin目录,查看vbjc.config,就知道具体使用了哪些jar包。一试果然成功。

   后面的事情就进展顺利多了。

   下面是编写好的build.xml。

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="appframe3" default="build" basedir="">

 <!-- ******************************************************** -->
 <!-- * Copyright 2004 AIC CO.,LD. All rights reserved.      * -->
 <!-- * Author: asiainfo shanghai fanhuan                    * -->
 <!-- *                                                      * -->
 <!-- ******************************************************** -->
 <!-- * Targets:                                             * -->
 <!-- * idl2java     Generate idl file to java file          * -->
 <!-- * corbaJavc    Compile java file                       * -->
 <!-- * corbaJar     Add class into jar                      * -->
 <!-- * autoGen      Generate bo file                     * -->
 <!-- *                                                      * -->
 <!-- * copy         Copy config file to application dir  * -->
 <!-- * build        Build application                       * -->
 <!-- * war          Web Application Archive                 * -->
 <!-- *                                                      * -->
 <!-- ******************************************************** -->

 <property name="app.name" value="openbusi" />
 <property name="src.dir" value="src" />
 <property name="config.dir" value="config" />
 <property name="bosrc.dir" value="idlsrc" />
 <property name="bin.dir" value="bin" />
 <property name="lib.dir" value="lib" />
 <property name="idl.dir" value="../../../aicbs21/idl" />
 <property name="webroot.dir" value="webroot" />
 <property name="WEB-INF.dir" value="${webroot.dir}/WEB-INF" />
 <property name="classes.dir" value="${WEB-INF.dir}/classes" />
 <property name="idlSrc.dir" value="${bin.dir}/corbaclient" />
 <property name="idlClasses.dir" value="${bin.dir}/classes" />
 <property name="autoGen.dir" value="${bin.dir}/autogen" />

 <property name="package" value="com.ai.openbusi.stub" />
 <property name="package.dir" value="
//com//ai//openbusi//stub//" />


 <path id="corba.classpath">
  <pathelement location="${lib.dir}/corba/asrt.jar" />
  <pathelement location="${lib.dir}/corba/jdsserver.jar" />
  <pathelement location="${lib.dir}/corba/obd_vb.jar" />
  <pathelement location="${lib.dir}/corba/vbejb.jar" />
  <pathelement location="${lib.dir}/corba/vbjorb.jar" />
  <pathelement location="${lib.dir}/corba/vbsec.jar" />
  <pathelement location="${lib.dir}/corba/xmlrt.jar" />
 </path>

 <path id="autogen.classpath">
  <pathelement location="${lib.dir}/idl2java.jar" />
  <pathelement location="${autoGen.dir}/idltobo.jar" />
 </path>

 <path id="build.classpath">
  <pathelement location="${lib.dir}/AIResourceLib.jar" />
  <pathelement location="${lib.dir}/appframe3_20051029.jar" />
  <pathelement location="${lib.dir}/borlandxml.jar" />
  <pathelement location="${lib.dir}/bsh-1.3.0.jar" />
  <pathelement location="${lib.dir}/commons-beanutils.jar" />
  <pathelement location="${lib.dir}/commons-collections-3.0.jar" />
  <pathelement location="${lib.dir}/commons-configuration-1.0-dev.jar" />
  <pathelement location="${lib.dir}/commons-lang-2.0.jar" />
  <pathelement location="${lib.dir}/commons-logging.jar" />
  <pathelement location="${lib.dir}/concurrent.jar" />
  <pathelement location="${lib.dir}/ecs-1.4.2.jar" />
  <pathelement location="${lib.dir}/idl2java.jar" />
  <pathelement location="${lib.dir}/jasperreports-0.5.2.jar" />
  <pathelement location="${lib.dir}/jbcl.jar" />
  <pathelement location="${lib.dir}/jdom.jar" />
  <pathelement location="${lib.dir}/jndi-1.2.1.jar" />
  <pathelement location="${lib.dir}/lm.jar" />
  <pathelement location="${lib.dir}/log4j-1.2.8.jar" />
  <pathelement location="${lib.dir}/obd.jar" />
  <pathelement location="${lib.dir}/ojdbc14.jar" />
  <pathelement location="${lib.dir}/poi-2.5.1-final-20040804.jar" />
  <pathelement location="${lib.dir}/rowset.jar" />
  <pathelement location="${lib.dir}/servlet.jar" />
  <pathelement location="${lib.dir}/smart.jar" />
  <pathelement location="${lib.dir}/uitheme-1.4.jar" />
  <pathelement location="${lib.dir}/vbjorb.jar" />
  <pathelement location="${lib.dir}/vbsec.jar" />
  <pathelement location="${lib.dir}/velocity-1.4-rc1.jar" />
  <pathelement location="${lib.dir}/xerces.jar" />
  <pathelement location="${lib.dir}/pool.jar" />
  <pathelement location="${lib.dir}/commons-fileupload-1.0.jar" />
 </path>


 <target name="idl2java">
  <property name="arg" value=" -package ${package} -root_dir ${idlSrc.dir}
   -comments -bind -no_examples -no_tie " />
  <!-- start add idl file -->
  <exec dir="" executable="idl2java.exe" os="Windows XP">
   <arg line="${arg} ${idl.dir}/cbscommon_def.idl
                ${idl.dir}/sysclass_def.idl
                ${idl.dir}/privmgnt_def.idl
             ${idl.dir}/privmgnt.idl
    ${idl.dir}/publicframe_mgr.idl
    ${idl.dir}/privext.idl
    ${idl.dir}/privmgnt_other.idl
    ${idl.dir}/sysclass_other.idl
    ${idl.dir}/busiaccept_def.idl
    ${idl.dir}/busiaccept_def2.idl
    ${idl.dir}/busiaccept_other.idl
    ${idl.dir}/busiaccept.idl
    ${idl.dir}/busicommon.idl
    ${idl.dir}/busichange.idl
    ${idl.dir}/busicreate.idl
    ${idl.dir}/busiseek.idl
    " />
  </exec>
  <!-- end add idl file -->
 </target>


 <target name="corbaJavac" depends="idl2java">
  <mkdir dir="${idlClasses.dir}"/>
  <javac srcdir="${idlSrc.dir}" destdir="${idlClasses.dir}">
   <classpath refid="corba.classpath" />
  </javac>
 </target>

 <target name="corbaJar" depends="corbaJavac">
  <jar destfile="${lib.dir}/idl2java.jar" basedir="${idlClasses.dir}" excludes="readme.txt" />
 </target>

 <target name="autoGen" depends="corbaJar">
  <copydir src="${bosrc.dir}" dest="${idlSrc.dir}" includes="**/*.java" excludes="readme.txt"/>
  <java classname="com.ai.autogen.AutoGen">
   <arg value="${idlSrc.dir}${package.dir}" />
   <arg value="${config.dir}${package.dir}" />
   <arg value="${package}" />
   <classpath refid="autogen.classpath" />
  </java>
  <copydir src="${config.dir}${package.dir}" dest="${src.dir}${package.dir}" includes="**/*.java" />
 </target>

 <target name="clean" depends="">
  <delete includeemptydirs="true">
   <fileset dir="${src.dir}${package.dir}" includes="**/*.java"/>
   <fileset dir="${idlSrc.dir}" includes="**/*.java"/>
   <fileset dir="${idlClasses.dir}" includes="**/*.class"/>
   <fileset dir="${config.dir}" includes="**/*.bo"/>
   <fileset dir="${config.dir}" includes="**/*.java"/>
   <fileset dir="${classes.dir}" includes="**/*.class"/>
   <fileset dir="${classes.dir}" includes="**/*.bo"/>
  </delete>
  <delete file="${lib.dir}/idl2java.jar"/>
 </target>

 <target name="copy" description="">
  <copydir src="${config.dir}" dest="${classes.dir}" excludes="**/*.java"/>
  <copydir src="${lib.dir}" dest="${WEB-INF.dir}/lib" includes="**/*.jar"/>
 </target>

 <target name="build" depends="copy">
  <javac srcdir="${src.dir}" destdir="${classes.dir}">
   <classpath refid="build.classpath" />
  </javac>
 </target>

 <target name="war" depends="build">
  <delete includeEmptyDirs="true" dir="${app.name}.war" />
  <war destfile="${app.name}.war" webxml="${WEB-INF.dir}/web.xml" compress="false">
   <fileset dir="${webroot.dir}" />
  </war>
 </target>

</project>

阅读更多
个人分类: 工作笔记
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭