使用Maven管理依赖JAR文件,自定义项目布局,利用ANT生成不同的发布包
<?xml version="1.0" encoding="GB2312"?>
<project name="CardInfo-WebApp" default="build_all" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant"> <property file="build.properties"/> <target name="build_all" depends="zip, war, war_patch, zip_library" description="build project and create zip file of publish.">
<delete includeemptydirs="true" dir="${target.basedir}" includes="**/*" excludes="/*.zip, /*.war" />
</target> <target name="build_app" depends="zip" description="build project and create zip file of publish.">
<delete includeemptydirs="true" dir="${target.basedir}" includes="**/*" excludes="/*.zip" />
</target> <target name="build_war" depends="war" description="build project and create war file of publish.">
<delete includeemptydirs="true" dir="${target.basedir}" includes="**/*" excludes="/*.war" />
</target> <target name="build_war_patch" depends="war_patch" description="build project and create war file of publish.">
<delete includeemptydirs="true" dir="${target.basedir}" includes="**/*" excludes="/*.war" />
</target> <target name="build_library" depends="zip_library" description="copy jar resource and create zip file.">
<delete includeemptydirs="true" dir="${target.basedir}" includes="**/*" excludes="/*.zip" />
</target> <tstamp prefix="build.">
<format property="time" pattern="yyyy-MM-dd HH:mm" />
<format property="timestamp" pattern="yyyyMMddHHmm"/>
</tstamp> <target name="init_maven">
<echo message="init maven config. local repository is: ${M2_REPO}"/>
<path id="maven-ant-tasks.classpath" path="${M2_REPO}/org/apache/maven/maven-ant-tasks/2.1.3/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" /> <artifact:localRepository id="local.repository" path="${M2_REPO}"/> <artifact:pom id="maven.project" file="pom.xml" /> <artifact:dependencies pathId="classpath.build" filesetid="maven.fileset.build">
<localRepository refid="local.repository"/>
<pom refid="maven.project" />
</artifact:dependencies> <artifact:dependencies pathId="classpath.runtime" filesetid="maven.fileset.runtime" usescope="runtime">
<localRepository refid="local.repository"/>
<pom refid="maven.project"/>
</artifact:dependencies> <artifact:dependencies pathId="classpath.provided" filesetid="maven.fileset.provided" scopes="provided">
<localRepository refid="local.repository"/>
<pom refid="maven.project" />
</artifact:dependencies>
</target> <target name="init_path" depends="init_maven">
<echo>*********************************</echo>
<echo>Maven build project base directory is ${maven.project.basedir}</echo>
<echo>Maven build project source directory is ${maven.project.build.sourceDirectory}</echo> <echo>*********************************</echo>
<property name="project.application.basedir" value="${maven.project.basedir}/Application" />
<echo>Maven build project application directory is ${project.application.basedir}</echo> <property name="project.path.tools" value="${project.application.basedir}}/tools"/>
<echo>Maven build project application tools directory is ${project.path.tools}</echo> <property name="project.path.webapps" value="${project.application.basedir}/webapps"/>
<echo>Maven build project application webapps directory is ${project.path.webapps}</echo>
<property name="project.path.webapps.webinf" value="${project.path.webapps}/WEB-INF"/> <property name="project.path.conf" value="${project.path.webapps.webinf}/conf"/>
<echo>Maven build project application conf directory is ${project.path.conf}</echo> <property name="project.path.lib" value="${project.path.webapps.webinf}/lib"/>
<echo>Maven build project application jar lib directory is ${project.path.lib}</echo> <property name="project.path.log" value="${project.path.webapps.webinf}/log"/>
<echo>Maven build project application log directory is ${project.path.log}</echo> <property name="project.path.workspace" value="${project.path.webapps.webinf}/workspace"/>
<echo>Maven build project application workspace directory is ${project.path.workspace}</echo> <echo>*********************************</echo>
<property name="target.basedir" value="${maven.project.basedir}/target"/>
<mkdir dir="${target.basedir}"/>
<echo>Maven build target base directory is ${target.basedir}</echo> <property name="target.path.build" value="${target.basedir}/build"/>
<mkdir dir="${target.path.build}"/>
<echo>Maven build target build directory is ${target.path.build}</echo> <property name="target.path.classes" value="${target.path.build}/classes"/>
<mkdir dir="${target.path.classes}"/>
<echo>Maven build target classes directory is ${target.path.classes}</echo> <property name="target.path.tools" value="${target.path.build}/tools"/>
<mkdir dir="${target.path.tools}"/>
<echo>Maven build target tools directory is ${target.path.tools}</echo> <property name="target.path.webapps" value="${target.path.build}/webapps"/>
<mkdir dir="${target.path.webapps}"/>
<echo>Maven build target webapps directory is ${target.path.webapps}</echo> <property name="target.path.webapps.webinf" value="${target.path.webapps}/WEB-INF"/>
<mkdir dir="${target.path.webapps.webinf}"/> <property name="target.path.conf" value="${target.path.webapps.webinf}/conf"/>
<mkdir dir="${target.path.conf}"/>
<echo>Maven build target conf directory is ${target.path.conf}</echo> <property name="target.path.lib" value="${target.path.webapps.webinf}/lib"/>
<mkdir dir="${target.path.lib}"/>
<echo>Maven build target lib directory is ${target.path.lib}</echo> <property name="target.path.log" value="${target.path.webapps.webinf}/log"/>
<mkdir dir="${target.path.log}"/>
<echo>Maven build target log directory is ${target.path.log}</echo> <property name="target.path.webapps.classes" value="${target.path.webapps.webinf}/classes"/>
<mkdir dir="${target.path.webapps.classes}"/> <property name="target.path.webapps.template" value="${target.path.webapps.webinf}/template"/>
<mkdir dir="${target.path.webapps.template}"/>
<echo>Maven build target template directory is ${target.path.webapps.template}</echo> <property name="target.path.workspace" value="${target.path.webapps.webinf}/workspace"/>
<mkdir dir="${target.path.workspace}"/>
<echo>Maven build target workspace directory is ${target.path.workspace}</echo>
</target> <target name="init_build_var" depends="init_maven">
<property name="compile.debug" value="false" />
<property name="compile.deprecation" value="false" />
<property name="compile.optimize" value="true" />
<property name="compile.encoding" value="UTF-8" />
<property name="compile.sourceversion" value="1.6" />
<property name="compile.targetversion" value="1.6" /> <property name="build.version" value="${maven.project.version}-Build${build.timestamp}"/>
<echo>Maven build version is ${build.version}</echo> <property name="patch.version" value="${maven.project.version}-Patch${build.timestamp}"/>
<echo>Maven build version is ${build.version}</echo> <property name="build.jar.name" value="${maven.project.artifactId}.jar" />
<echo>Maven build target zip file name is ${build.zip.name}</echo> <property name="build.zip.name" value="${maven.project.artifactId}-${build.version}.zip" />
<echo>Maven build target zip file name is ${build.zip.name}</echo> <property name="build.war.name" value="${maven.project.artifactId}-${build.version}.war" />
<echo>Maven build target war file name is ${build.war.name}</echo> <property name="patch.war.name" value="${maven.project.artifactId}-${patch.version}.war" />
<echo>Maven build target patch-war file name is ${patch.war.name}</echo>
</target> <target name="compile" description="compile java source to target classes path." depends="init_path, init_build_var">
<echo>compile java source.</echo>
<echo>source version is ${compile.sourceversion}</echo>
<echo>target version is ${compile.targetversion}</echo>
<javac srcdir="${maven.project.build.sourceDirectory}" destdir="${target.path.webapps.classes}"
source="${compile.sourceversion}" target="${compile.targetversion}"
description="${compile.deprecation}" optimize="${compile.optimize}"
debug="${compile.debug}" encoding="${compile.encoding}"
>
<classpath refid="classpath.build"/>
<classpath refid="classpath.provided"/>
<classpath refid="classpath.runtime"/>
</javac>
<!-- jar destfile="${target.path.lib}/${build.jar.name}" basedir="${target.path.classes}">
<manifest>
<attribute name="Version" value="${maven.project.version}" />
<attribute name="Build-by" value="${build.timestamp}" />
</manifest>
</jar -->
</target> <target name="copy_library" description="copy jar library to target lib path" depends="init_path">
<copy todir="${target.path.lib}">
<fileset refid="maven.fileset.runtime"/>
<fileset dir="${project.path.lib}" />
<mapper type="flatten" />
</copy>
</target> <target name="copy_resource" description="copy resource file to target classes path" depends="init_path">
<copy todir="${target.path.webapps.classes}" includeemptydirs="false">
<fileset dir="${maven.project.build.sourceDirectory}">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copydir dest="${target.path.webapps}" src="${project.path.webapps}" excludes="/WEB-INF/**/*"/>
<copydir dest="${target.path.webapps.webinf}" src="${project.path.webapps.webinf}">
<exclude name="/classes/**/*"/>
<exclude name="/work/**/*"/>
<exclude name="/tmp/**/*"/>
<exclude name="/temp/**/*"/>
</copydir>
<copydir dest="${target.path.build}" src="${project.application.basedir}">
<exclude name="/webapps/**/*"/>
<exclude name="/${target.path.classes}"/>
</copydir>
</target>
<target name="copy_resource_noconfig" description="copy resource file to target classes path" depends="init_path">
<copy todir="${target.path.webapps.classes}">
<fileset dir="${maven.project.build.sourceDirectory}">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copydir dest="${target.path.webapps}" src="${project.path.webapps}" excludes="/WEB-INF/**/*"/>
<copydir dest="${target.path.webapps.webinf}" src="${project.path.webapps.webinf}">
<exclude name="/classes/**/*"/>
<exclude name="/work/**/*"/>
<exclude name="/tmp/**/*"/>
<exclude name="/temp/**/*"/>
<exclude name="/conf/**/*"/>
<exclude name="/log/**/*"/>
<exclude name="/workspace/**/*"/>
<exclude name="/lib/**/*"/>
</copydir>
<copydir dest="${target.path.build}" src="${project.application.basedir}">
<exclude name="/webapps/**/*"/>
<exclude name="/${target.path.classes}"/>
</copydir>
</target> <target name="clean" description="clean build directory." depends="init_path">
<echo>clean build directory : ${target.basedir}</echo>
<delete includeemptydirs="true" dir="${target.basedir}" includes="**/*" />
</target> <target name="zip" description="create published zip file" depends="init_path, init_build_var, compile, copy_library, copy_resource">
<zip destfile="${target.basedir}/${build.zip.name}">
<fileset dir="${target.path.build}"></fileset>
</zip>
</target>
<target name="zip_library" description="create published zip file" depends="init_path, init_build_var, copy_library">
<zip destfile="${target.basedir}/library.zip">
<fileset dir="${target.path.lib}"></fileset>
</zip>
</target> <target name="war" description="create published war file" depends="init_path, init_build_var, compile, copy_library, copy_resource">
<war destfile="${target.basedir}/${build.war.name}">
<fileset dir="${target.path.webapps}"></fileset>
<manifest>
<attribute name="Version" value="${maven.project.version}" />
<attribute name="Build-by" value="${build.timestamp}" />
</manifest>
</war>
</target> <target name="war_patch" description="create published war file for update" depends="init_path, init_build_var, compile, copy_resource_noconfig">
<war destfile="${target.basedir}/${patch.war.name}">
<fileset dir="${target.path.webapps}"></fileset>
<manifest>
<attribute name="Version" value="${maven.project.version}" />
<attribute name="Build-by" value="${build.timestamp}" />
</manifest>
</war>
</target>
</project>
使用Maven管理依赖JAR文件,自定义项目布局,利用ANT生成不同的发布包的更多相关文章
- WebMagic基础与Maven管理依赖
2. 快速开始 WebMagic主要包含两个jar包:webmagic-core-{version}.jar和webmagic-extension-{version}.jar.在项目中添加这两个包的依 ...
- maven手动增加jar文件
maven手动增加jar文件 在cmd界面输入: mvn install:install-file -Dfile=D:\com.ibm.mq.jar -DgroupId=com.ibm.mq -Dar ...
- Maven打包成Jar文件时依赖包的问题
我们项目中使用到第三方的库文件,这些jar库文件并没有放到Maven中央库上,导致我们需要在项目中自己配置使用.我们的两三个开发人员对Java都是很熟,因此在使用中遇到了一些问题,表现在:在本地中引入 ...
- maven无法下依赖jar文件的解决方案
问题描述: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be ...
- 转】[1.0.2] 详解基于maven管理-scala开发的spark项目开发环境的搭建与测试
场景 好的,假设项目数据调研与需求分析已接近尾声,马上进入Coding阶段了,辣么在Coding之前需要干马呢?是的,“统一开发工具.开发环境的搭建与本地测试.测试环境的搭建与测试” - 本文详细记录 ...
- maven管理本地jar包
maven作为包管理工具,好处不必多说.但是有些情况,比如需要引入第三方包,如快递鸟,支付宝,微信等jar包(当然有可能直接提供maven依赖),如果直接下载到本地之后,怎么整合到自己的maven工程 ...
- Maven 导出依赖Jar,生成source.jar,javadoc.jar
下载最新版的Maven http://maven.apache.org/download.cgi 解压到本地文件夹 新建环境变量 MAVEN_HOME maven解压目录 在path加 ...
- ssm框架整合配置,用maven配置依赖jar包
1.创建maven project 首先在pom.xml中指定工程所依赖的jar包 <project xmlns="http://maven.apache.org/POM/4.0.0& ...
- maven管理本地jar包注意事项
今天lucene中集成第三方中文分词器IKAnalyzer的时候遇到了相似的问题:lucene版本4.9.IKAnalyzer版本2012FF_hf1 直接去maven仓库下载,pom配置如下: &l ...
随机推荐
- Android学习之 WebView使用小结
这段时间基于项目须要 在开发中与WebView的接触比較多,前段时间关于HTML5规范尘埃落定的消息出如今各大IT社区头版上,更有人说:HTML5将颠覆原生App开发 尽管我不太认同这一点 可是关于H ...
- InstallShield集成安装MSDE2000最小版本(一) fishout特许授权发布
原文:InstallShield集成安装MSDE2000最小版本(一) fishout特许授权发布 原帖地址:http://blog.csdn.net/fishout/archive/2009/10/ ...
- 快速构建Windows 8风格应用8-贴靠视图
原文:快速构建Windows 8风格应用8-贴靠视图 本篇博文主要介绍如何切换出贴靠视图.关于贴靠视图的设计.关于贴靠视图的应用程序栏和如何实现贴靠视图. 如何切换出贴靠视图 第一步:水平方向全屏视图 ...
- 《那些年,我们拿下FPGA》做笔记
spld.cpld和fpga等可不管什么样的逻辑是大自然来实现.任何逻辑可以由多项式来表示(要么逼关闭).比多项式乘法和处理操作仅此而已. 而就.您可以在门线上用.或门添加剂. fpga扩展架构SOP ...
- 使用sqlldr向Oracle导入大的文本(txt)文件
我们有多种方法可以向Oracle数据库里导入文本文件,但如果导入的文本文件过大,例如5G,10G的文本文件,有些方法就不尽如意了,例如PLSQL Developer中的导入文本功能,如果文本文件过大, ...
- 有return如果是try catch finally运行命令
背景: 昨天一个朋友出去采访,遇到这样的问题:"C# catch那里return.finally也弄它运行?" 个人总结实践: 1.无论有木有出现异常.finally块中代码都会 ...
- leetcode第28题--Divide Two Integers
Divide two integers without using multiplication, division and mod operator. 分析:题目意思很容易理解,就是不用乘除法和模运 ...
- 整理 W3CSchool 常用的CSS属性列表
近期教学给学员总结常用的CSS属性,方便学习查询,正好发上来也给大家分享一下,O(∩_∩)O. 摘选自:http://www.w3cschool.com.cn/ 表格最右列的数字标识支持的CSS最低版 ...
- ASP.NET请求处理过程
当请求一个*.aspx文件的时候,这个请求会被inetinfo.exe进程截获,它判断文件的后缀(aspx)之后,将这个请求转交给Aspnet_isapi.dll,aspnet_isapi.dll会通 ...
- 如何用VB获得Windows各类系统目录
现在有很多关于如何用VB获得Windows目 录的文章,但大都只讲到如何获得Windows目录和System目录,有时候我们却需要获得像"我的文档"这样的目录("我的文档 ...