`
shuidexiongdi
  • 浏览: 73405 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

ant-built

    博客分类:
  • ant
 
阅读更多

第一次用ant编写打包命令,写下纪念

 

<?xml version="1.0" encoding= "UTF-8" ?>
<project name="myweb_project" default="dist" basedir=".">
	
	<!--
		该项目需要jdk1.5以上的编译器进行编译
	-->
	<property name="java_home" value="C:\jdk5"></property>
	
	<!-- 定义项目变量 -->
	<property name="project" value="myweb"></property>
	<property name="project_root" value="."/>
	<property name="project_src" value="${project_root}\src"/>
	<property name="project_webcontent_name" value="WebContent"/>
	
	<!-- 定义项目依赖的各个包的路径变量-->
	<property name="project_lib" value="${project_root}\${project_webcontent_name}\WEB-INF\lib"/>
	<property name="jboss_home" value="E:\jboss"/>
	<property name="jboss_lib" value="${jboss_home}\lib"/>
	<property name="jboss_client_lib" value="${jboss_home}\client"/>
	
	<!-- 定义打包输出路径 -->
	<property name="duilt_dir" value="E:\autoBiult"/>
	<property name="dest" value="${duilt_dir}\myweb_dest"/>
	<property name="classes" value="${dest}/WEB-INF/classes"/>
	
	<!-- 定义打包的后缀 -->
	<property name="suffix" value="war"/>
    
    <!-- 定义发布路径 -->
	<property name="deploy_path" value="${jboss_home}\server\default\deploy"/>
	

	<!-- 设置项目的类路径:将各个依赖包包含进来 -->
	<path id="myweb.project.class.path">
		<fileset dir="${project_lib}">
			<include name="**/*.jar"/>
		</fileset>
		<fileset dir="${jboss_lib}">
			<include name="**/*.jar"/>
		</fileset>
		<fileset dir="${jboss_client_lib}">
			<include name="**/*.jar"/>
		</fileset>
	</path>
	
	<!-- 判断源码是否存在 -->
	<condition property="project_src_exist">
		<and>
			<available file="${project_src}" type="dir"/>
		</and>
	</condition>
	
	<!-- 判断打包路径是否存在 -->
	<condition property="dest_exist">
		<and>
			<available file="${dest}" type="dir"/>
		</and>
	</condition>
	
	<!-- 判断webContent是否存在 -->
	<condition property="webcontent_exist">
		<and>
			<available file="${project_root}\${project_webcontent_name}" type="dir"/>
		</and>
	</condition>
	
	<!-- 判断发布目录是否存在 -->
	<condition property="deployFolderIsExist">
		<and>
			<available file="${deploy_path}\${project}.${suffix}" type="file"/>
		</and> 
	</condition>

	<target name="test_src" unless="project_src_exist">
		<echo message="the folder src was not exist!"/>
		<echo message="generate the fold! ${project_src}"/>
		<mkdir dir="${project_src}" />
	</target>
	
	<target name="test_webcontent_exist" unless="webcontent_exist">
		<echo message="the folder WebContent was not exist!"/>
		<echo message="generate the fold! ${project_root}\${project_webcontent_name}"/>
		<mkdir dir="${project_root}\${project_webcontent_name}" />
	</target>

	<!-- 编译前的准备 -->
	<target name="complile_prepare" depends="test_src,test_webcontent_exist">
		<echo message="compile prepare"/>
		<echo message="make dir ${classes}"/>
		<mkdir dir="${classes}"/>
	</target>

	<!-- 开始编译 -->
	<target name="compile" depends="complile_prepare">
		<echo message="compile source file in the src dir"/>
		<echo message="compile java home : ${java_home}"/>
		<javac encoding="UTF-8" srcdir="${project_src}" destdir="${classes}" debug="on"
			executable="${java_home}/bin/javac.exe" fork="yes" memoryInitialSize="128m" memoryMaximumSize="512m">
			<classpath>
				<path refid="myweb.project.class.path"/>
			</classpath>
		</javac>
	</target>

	<!-- 拷贝webContent里面的内容 -->
	<target name="copy_webcontent" depends="compile">
		<echo message="copy webcontent to ${dest}"/>
		<copy todir="${dest}">
			<fileset dir="${project_root}\${project_webcontent_name}">
				<exclude name="**/*.java"/>
			</fileset>
		</copy>
	</target>
   
	<!-- 拷贝classes下的内容-->
	<target name="copy_classes" depends="compile">
		<echo message="copy classes to ${classes}"/>
		<copy todir="${classes}">
			<fileset dir="${project_src}">
				<exclude name="**/*.java"/>
			</fileset>
		</copy>
	</target>

	<!--发布-->
	<target name="deploy" depends="copy_webcontent,copy_classes">
		<echo message="================deploy to ${deploy_path}\${project}.${suffix}===============">
		</echo>
		<copy todir="${deploy_path}\${project}.${suffix}">
			<fileset dir="${dest}">
				<include name="**"/>
				<exclude name="**/*Test.class"/>
			</fileset>
		</copy>
		<echo message="deploy success"/>
	</target>
	
	<!-- 打包 -->
	<target name="dist" depends="copy_webcontent,copy_classes" description="package project">
		<echo message="=========jar to ${duilt_dir}\${project}.${suffix}==========="/>
		<jar destfile="${duilt_dir}\${project}.${suffix}" basedir="${dest}" includes="**" excludes="**/*Test.class"/>
		<echo message="=========jar success==========="/>
	</target>

	<!-- 清理 -->
	<target name="clean_dest" description="clean project">
		<echo message="=========clean ${dest}==========="/>
		<delete dir="${dest}"/>
		<delete file="${duilt_dir}\${project}.${suffix}"/>
	</target>

	<!-- 清理发布文件 -->
	<target name="clean_deploy" description="clean deploy">
		<echo message="=========clean ${deploy_path}\${project}.${suffix}==========="/>
		<delete dir="${deploy_path}\${project}.${suffix}"/>
	</target>

	
</project>
 
分享到:
评论

相关推荐

    ant的build配置文件

    Ant是Apache组织开发的一款Java构建工具,它使用XML来定义构建过程,这使得构建脚本易于理解和维护。本文将深入探讨Ant的build配置文件及其在软件开发中的应用。 Ant的build配置文件通常命名为`build.xml`,它是...

    using-pre-built-react-components:用CodeSandbox创建

    本项目“using-pre-built-react-components”似乎是一个教程或示例,指导如何在CodeSandbox中利用预构建的React组件。以下是一些关键知识点: 1. **React组件**:React组件是可重用的代码块,它们像JavaScript函数...

    ant使用指南

    &lt;attribute name="Built-By" value="${user.name}"/&gt; &lt;attribute name="Main-class" value="package.Main"/&gt; ``` Ant还有`tstamp`任务,可以生成时间戳属性,例如: ```xml ``` 这些时间戳属性可以在文件...

    ant学习打包代码

    &lt;attribute name="Built-By" value="${user.name}" /&gt; &lt;attribute name="Main-Class" value="com.test.Test1" /&gt; &lt;!--删除jar--&gt; ${dist}/package1-${TSTAMP}.jar"/&gt; &lt;!--拷貝--&gt; ...

    使用ant部署eclipse开发的web工程到tomcat

    &lt;attribute name="Built-By" value="${user.name}"/&gt; ${build.dir}/${ant.project.name}.war" webxml="${webapp.dir}/WEB-INF/web.xml"&gt; ${webapp.dir}"/&gt; ${classes.dir}"/&gt; &lt;!-- 部署到Tomcat --&gt; ...

    Ajax基础教程源码

    also contains a build.xml file from which the WAR file can be built using Ant. Use the dist target to compile the sources and build the WAR file: &gt; ant dist Each chapter WAR file has an index file ...

    maven-and-osgi

    In terms of capabilities, Maven is an improvement to Apache Ant-thanks to numerous plug-ins and built-in integration with unit testing frameworks such as JUnit. Tired of writing the same build logic ...

    maven学习资料,通过这基本书可以很快上手,包含chm文档

    In terms of capabilities, Maven is an improvement to Apache Ant-thanks to numerous plug-ins and built-in integration with unit testing frameworks such as JUnit. Tired of writing the same build logic ...

    基于angular8AntDesign搭建的多页面后台管理系统

    Fast development platform based on angular8, ng.ant.design built multi-tab page background management system &#40;continuous upgrade&#41; ^_^

    Ajax 基礎教程 (Foundations of Ajax)

    also contains a build.xml file from which the WAR file can be built using Ant. Use the dist target to compile the sources and build the WAR file: &gt; ant dist Each chapter WAR file has an index file ...

    NetBeans™ IDE Field Guide: Developing Desktop, Web, Enterprise, and Mobile Applications, Second Edition(1)

    including &lt;br&gt;Taking advantage of the Ant-based project system to create easily deployable projects &lt;br&gt;Developing web applications with the built-in Apache Tomcat web server &lt;br&gt;...

    制冷片LCC12-10-16LS

    Built w higher time (&lt; Superio High st RTV se Lapped Hot Sid ∆ Tma Qmax Imax ( Vmax AC Res ECHNI l office or vis C12-10 e-Stage The EU Complia CAL PERFOR DUCT FEATU state reliability. ith high tempe ...

    Android代码-phonegap-android

    PhoneGap Android is an Android application library that allows for PhoneGap-based projects to be built for the Android Platform. PhoneGap-based applications are, at the core, an application written in...

    Manning - Eclipse In Action.pdf

    - **Editing and Formatting**: Techniques for editing and formatting source code efficiently using Eclipse's built-in tools. - **Code Navigation**: Features that help navigate through large codebases, ...

    jpi.tar.gz

    plugin.jpi', 'build-timeout.jpi', 'built-on-column.jpi', 'categorized-view.jpi', 'cloudbees-folder.jpi', 'command-launcher.jpi', 'conditional-buildstep.jpi', 'credentials-binding.jpi', 'credentials....

    Maven-The Complete Reference.pdf

    - **Dependency Management:** Maven provides a built-in dependency management system, whereas Ant relies on external tools like Ivy for dependency management. - **Automation:** Maven automates many ...

    spring-boot-reference.pdf

    13.4. Ant 13.5. Starters 14. Structuring Your Code 14.1. Using the “default” Package 14.2. Locating the Main Application Class 15. Configuration Classes 15.1. Importing Additional Configuration ...

    vue-lazy-img:Vue + Webpack的延迟加载映像

    Vue.js 是一个流行的前端JavaScript框架,用于构建用户界面。它以其声明式编程、组件化以及易用性而受到开发者喜爱。Webpack 是一个模块打包器,它将应用中的各种资源(如JavaScript、CSS、图片等)打包成浏览器可以...

Global site tag (gtag.js) - Google Analytics