写个完整的打包成可执行jar的build.xml文件

写个完整的打包成可执行jar的build.xml文件

  1  < project  default ="run"  basedir ="." >
  2 
  3       < property  name ="name.run"  value ="demo"   />
        <!--class has main function-->
  4       < property  name ="main-class"  value ="com.dev.cui.main.Entrance"   />
  5 
  6       < property  environment ="env"   />
  7 
  8       < property  name ="debug"  value ="off"   />
  9       < property  name ="optimize"  value ="on"   />
 10       < property  name ="description"  value ="on"   />
 11 
 12       < property  name ="src.dir.prefix"  value ="${basedir}" />
 13       < property  name ="src.dir"  value ="${src.dir.prefix}/conf;${src.dir.prefix}/util;${src.dir.prefix}/dao;${src.dir.prefix}/service;${src.dir.prefix}/main"   />
 14       < property  name ="lib.dir"  value ="${basedir}/lib"   />
 15       < property  name ="packages"  value ="com.jc.cxc.fact.*"   />
 16 
 17       < property  name ="build.dest"  value ="${basedir}/classes"   />
 18       < property  name ="build.javadocs"  value ="${basedir}/doc" />
 19 
 20       < property  name ="dist"  value ="${basedir}/dist"   />
 21      
 22       < property  name ="class_path"  value ="lib/ant-antlr-1.6.5.jar lib/asm.jar lib/asm-attrs.jar lib/cglib-2.1.3.jar lib/commons-beanutils.jar lib/commons-collections-2.1.1.jar lib/commons-logging-1.0.4.jar lib/dom4j-1.6.1.jar lib/firebirdsql-full.jar lib/log4j.jar lib/spring.jar" />
 23 
 24       <!--
 25      <path id="src.dir">
 26          <pathelement location="${src.dir.prefix}/generate"/>
 27          <pathelement location="${src.dir.prefix}/conf"/>
 28          <pathelement location="${src.dir.prefix}/dao"/>
 29          <pathelement location="${src.dir.prefix}/util"/>
 30          <pathelement location="${src.dir.prefix}/ui"/>
 31      </path>
 32       -->
 33 
 34       < path  id ="project.common.classpath" >
 35           < pathelement  path ="${jsdk_jar}"   />
 36           < fileset  dir ="${lib.dir}" >
 37               < include  name ="**/*.jar/"   />
 38           </ fileset >
 39       </ path >
 40 
 41       < target  name ="echo" >
 42           < tstamp  />
 43           < echo  message ="current.time=${TSTAMP}"   />
 44           < echo  message ="ant.java.version=${ant.java.version}"   />
 45       </ target >
 46 
 47       < target  name ="init"  depends ="clean, echo" >
 48           <!-- <delete dir="${build.dest}" /> -->
 49           <!-- <delete dir="${dist}"/> -->
 50           <!-- <delete dir="${build.javadocs}" /> -->
 51           < mkdir  dir ="${build.dest}"   />
 52           < mkdir  dir ="${dist}"   />
 53           < mkdir  dir ="${dist}/lib"   />
 54           < mkdir  dir ="${build.javadocs}"   />
 55       </ target >
 56 
 57       < target  name ="compile"  depends ="init" >
 58           < javac  srcdir ="${src.dir}"  destdir ="${build.dest}"  debug ="${debug}"  optimize ="${optimizze}" >
 59               < classpath  refid ="project.common.classpath"   />
 60           </ javac >
 61           <!--
 62          <copy file="${src.dir.prefix}/generate/hibernate.cfg.xml" todir="${build.dest}">
 63          </copy>
 64           -->
 65           < copy  todir ="${build.dest}" >
 66               < fileset  dir ="${src.dir.prefix}/conf" >
 67                   < exclude  name ="**/*.java" />
 68               </ fileset >
 69           </ copy >
 70       </ target >
 71 
 72       < target  name ="create.manifest" >
 73           <!--     <manifest file="${build.dest}">
 74              <attribute name="Main-Class" value="${main-class}"/>
 75          </manifest> -->
 76       </ target >
 77 
 78       < target  name ="jar.run"  depends ="compile" >
 79           < jar  jarfile ="${dist}/${name.run}.jar"  basedir ="${build.dest}"  includes ="**/*.*" >
 80               < manifest >
 81                   < attribute  name ="Main-Class"  value ="${main-class}" />
 82                   < attribute  name ="Class-Path"  value ="${class_path}" />
                      <!--to simply the class_path-->
 83  <!--             <attribute name="Class-Path" value="ant-antlr-1.6.5.jar asm.jar asm-attrs.jar cglib-2.1.3.jar commons-beanutils.jar commons-collections-2.1.1.jar commons-logging-1.0.4.jar dom4j-1.6.1.jar firebirdsql-full.jar log4j.jar spring.jar"/>
 84  -->
 85               </ manifest >
 86               <!---->
 87           </ jar >
 88       </ target >
 89 
 90       <!--
 91      <target name="run" depends="jar">
 92          <java classname="${main-class}">
 93              <classpath refid="project.common.classpath" />
 94          </java>
 95      </target>
 96  -->
 97       < target  name ="clean" >
 98           < delete  dir ="${build.dest}"   />
 99           < delete  dir ="${dist}"   />
100       </ target >
101 
102       < target  name ="run"  depends ="jar.run" >
103           < copy  todir ="${dist}/lib" ><!--according to class_path , which can keep struture clearly-->
104               < fileset  dir ="${lib.dir}" >
105  <!--
106                  <include name="ant-antlr-1.6.5.jar"/>
107                  <include name="asm.jar"/>
108                  <include name="asm-attrs.jar"/>
109                  <include name="cglib-2.1.3.jar"/>
110                  <include name="commons-beanutils.jar"/>
111                  <include name="commons-collections-2.1.1.jar"/>
112                  <include name="commons-logging-1.0.4.jar"/>
113                  <include name="dom4j-1.6.1.jar"/>
114                  <include name="firebirdsql-full.jar"/>
115                  <include name="log4j.jar"/>
116                  <include name="spring.jar"/>
117  -->
                      
<!--to simply the jar files-->
118                   < include  name ="*.jar" />
119               </ fileset >
120           </ copy >
121           < copy  todir ="${dist}" >
122               < fileset  dir ="${src.dir.prefix}" >
123                   < include  name ="sql.xml" /><!--sql.xml is xml structure to store sqls-->
124                   < include  name ="demo.bat" /> <!--demo.bat is bat file, for many times user default to run jar not using java, like others. Prefer to use bat, not directly click the jar file-->
125               </ fileset >
126           </ copy >
127       </ target >
128 
129  </ project >

你可能感兴趣的:(写个完整的打包成可执行jar的build.xml文件)