• Ant Build example.


    <?xml version="1.0" encoding="UTF-8"?>
    <project basedir="." default="usage" name="TestPrjAndBuild">
    	<!-- 定义目录变量 -->
    	<property name="project-name" value="TestPrjAndBuild" /> <!-- ====此处需要修改====.jar文件名 -->
    	<property name="src.dir" value="src" /> <!-- src -->
    	<property name="lib.dir" value="lib" /> <!-- lib -->
    	<property name="build.dir" value="bin" /> <!-- bin -->
    
    	<property name="jar-file-name" value="${project-name}.jar" />
    	<property name="main-class" value="com.test.MyMain" /> <!-- ====此处需要修改====main-class -->
    	<!-- 定义classpath -->
    	<path id="master-classpath">
    		<fileset dir="${lib.dir}">
    			<include name="**/*.jar" />
    		</fileset>
    		<pathelement path="${build.dir}"></pathelement>
    	</path>
    	<target description="Build file usage info (default task)" name="usage"> <!-- 默认执行的Task -->
    		<echo message=" " />
    		<echo message="  ${project-name} " />
    		<echo message="-------------------------------------------------------" />
    		<echo message="  Available Targets:" />
    		<echo message="  init    	- Init the directory" />
    		<echo message="  compile    - Compiles the source code" />
    		<echo message="  copy-res   - Copy the resources" />
    		<echo message="  jar        - Generate an .jar for source code" />
    		<echo message="  run        - Execute Main-Class" />
    		<echo message="  clean      - Delete class files and .jar file" />
    		<echo message="-------------------------------------------------------" />
    	</target>
    
    	<!-- 初始化${build.dir}目录 -->
    	<target name="init">
    		<mkdir dir="${build.dir}" />
    		<mkdir dir="${lib.dir}" />
    		<!-- 是否有lib目录,没有则加上 -->
    	</target>
    	<!-- 编译 -->
    	<target depends="init" name="编绎">
    		<javac encoding="UTF-8" debug="true" deprecation="on" destdir="${build.dir}"
    			listfiles="on" failonerror="true" srcdir="${src.dir}">
    			<classpath refid="master-classpath" />
    		</javac>
    
    	</target>
    	<!-- 复制资源文件 -->
    	<target name="复制资源文件">
    		<copy todir="${build.dir}">
    			<fileset dir="${src.dir}">
    				<exclude name="**/*.java" />
    			</fileset>
    		</copy>
    	</target>
    
    	<!-- 运行 -->
    	<target depends="编绎" name="运行">
    		<java classname="${main-class}" classpath="${build.dir}" fork="true"
    			maxmemory="256m">
    			<classpath refid="master-classpath" />
    			<sysproperty key="file.encoding" value="UTF-8" />
    			<arg value="-h" />
    		</java>
    	</target>
    	<!-- 生成jar包 -->
    	<target depends="编绎" name="打成jar包">
    		<jar basedir="${build.dir}" destfile="${jar-file-name}">
    			<manifest>
    				<attribute name="Main-Class" value="${main-class}" />
    				<attribute name="Class-Path" value="" />
    			</manifest>
    		</jar>
    	</target>
    	<!-- 清除 -->
    	<target name="clean">
    		<delete dir="${build.dir}" />
    		<delete file="${jar-file-name}" />
    	</target>
    </project>
    

  • 相关阅读:
    使用Spring Boot来加速Java web项目的开发
    Spring IOC的理解
    CentOS查看系统信息-CentOS查看命令
    mybatis传递Map和List集合示例
    java文件读写工具类
    MongoDB数据库操作
    linux中给PHP安装mongodb的扩展
    深度学习与计算机视觉系列(2)_图像分类与KNN
    深度学习与计算机视觉系列(3)_线性SVM与SoftMax分类器
    深度学习与计算机视觉系列(6)_神经网络结构与神经元激励函数
  • 原文地址:https://www.cnblogs.com/wucg/p/2002522.html
Copyright © 2020-2023  润新知