使用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 ...
随机推荐
- 基于protobuf的RPC实现
可以比较使用google protobuf RPC实现echo service可见.述. google protobuf仅仅负责消息的打包和解包.并不包括RPC的实现.但其包括了RPC的定义.如果有以 ...
- EXCEL导入GridView,然后再汇入数据库.
原文:EXCEL导入GridView,然后再汇入数据库. 近日项目中有一个多笔料号要输入,我做了一个用javascript复制输入框的功能,可以输入多笔料号. 但是使用者反馈,料号太多,可能几百个料号 ...
- ASP.NET中 RegularExpressValidator(正则验证)的使用
原文:ASP.NET中 RegularExpressValidator(正则验证)的使用 ylbtech-ASP.NET-Control-Validator: RegularExpressValida ...
- 关于WIN32.EXE变态木马下载器的解决办法
一.WIN32.EXE的来源:http://fdghewrtewrtyrew.biz/adv/130/win32.exe 二.运行后的表现:此WIN32.EXE通过80和8080端口访问若干个IP,若 ...
- 四种方案:将OpenStack私有云部署到Hadoop MapReduce环境中
摘要:OpenStack与Hadoop被誉为继Linux之后最有可能获得巨大成功的开源项目.这二者如何结合成为更猛的新方案?业内给出两种答案:Hadoop跑在OpenStack上或OpenStack部 ...
- leetcode第二题--Median of Two Sorted Arrays
Problem:There are two sorted arrays A and B of size m and n respectively. Find the median of the two ...
- 鼠标hover事件
JS: // ========== // = 鼠标hover事件 = // ========== function showHide (btn,box) { $(btn).hover(function ...
- Juqery遮罩插件
Juqery遮罩插件,想罩哪就罩哪! 一 前言 在项目开发时发现没有一个用起来 爽一点的遮罩插件,看起来觉得不难 好吧那就利用空闲时间,自己折腾一个吧,也好把jquery再温习一下, 需要的功能 ...
- SSIS Package to Call Web Service
原文 SSIS Package to Call Web Service SSIS Package to Call Web Service. You can Call WebService from S ...
- Memcache存储大量数据的问题
Memcache存储大数据的问题 huangguisu Memcached存储单个item最大数据是在1MB内,假设数据超过1M,存取set和get是都是返回false,并且引起性能的问题. 我们之 ...