老鬼的博客 来都来啦,那就随便看看吧~
ant打包war
发布于: 2019-03-05 更新于: 2019-11-23 分类于:  阅读次数: 

ant下载和配置

1.下载

1.png

2.配置环境变量

1
计算机--属性--高级系统设置--环境变量--系统变量--path

2.png

打包war

1.sp_war.bat

1
2
3
4
5
6
7
8
9
10
rem RenJie

D:
cd D:\my-tools\bat\ant
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181
set JRE_HOME=C:\Program Files\Java\jre1.8.0_181
rem end

ant -file sp_war.xml
pause

2.sp_war.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?xml version="1.0" encoding="UTF-8"?>

<!-- 定义一个工程,默认任务为warFile。 -->
<project name="salesplus" default="0 - default" basedir="D:/my-work/JavaProgram/tookeen/trunk/code" xmlns:artifact="antlib:org.apache.maven.artifact.ant">

<description>Builds, tests, and runs the project dsolrcloud.</description>


<!-- 项目名称 -->
<property name="project" value="salesplus"/>
<!-- 项目源代码目录 -->
<property name="src.dir" location="src/main/java"/>
<!-- javac编译后生成的class文件路径 -->
<property name="classes.dir" location="target/ant/wars/WEB-INF/classes" />
<!-- 最终生成war包的路径 -->
<property name="dist.dir" location="target/ant"/>
<!-- 项目配置文件路径 -->
<property name="config.dir" location="src/main/resources" />
<!-- 项目生产配置文件路径 -->
<property name="prod.config.dir" location="D:/my-work/JavaProgram/tookeen/trunk/doc/prod" />
<!-- 项目web页面路径 -->
<property name="web.root" location="src/main/webapp" />
<!-- maven-ant-tasks 下载maven依赖jar包的存放路径 -->
<property name="lib.dir" location="target/ant/wars/WEB-INF/lib"/>
<!-- 项目wars路径 -->
<property name="wars.dir" location="target/ant/wars" />




<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>

<!-- 清空文件夹 -->
<target name="1 - clean" description="清理ant编译文件">
<delete dir="target/ant/wars" />
</target>

<!-- 创建文件夹 -->
<target name="2 - makedir" description="建立文件夹">
<mkdir dir="${dist.dir}"/>
<mkdir dir="${wars.dir}"/>
<mkdir dir="${classes.dir}"/>
<mkdir dir="${lib.dir}"/>
</target>

<!-- 从pom下载jar包 -->
<target name="3 - lib" depends="2 - makedir" description="配置 ant 自动下载maven的依赖包 end ">
<!-- 下载maven依赖-->
<path id="maven-ant-tasks.classpath" path="D:/my-tools/bat/ant/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:dependencies filesetId="mavenlib" pathId="mavenclasspath" useScope="runtime">
<pom file="${basedir}/pom.xml" />
</artifact:dependencies>

<!-- pom下载jar -->
<copy todir="${lib.dir}">
<fileset refid="mavenlib" />
<mapper type="flatten" />
</copy>

<!-- 将WEB-INF/lib下的jar包copy到lib.dir -->
<copy todir="${lib.dir}">
<fileset dir="${web.root}/WEB-INF/lib" includes="**/*"/>
</copy>

</target>

<!-- 编译代码 -->
<target name="4 - compile" depends="3 - lib" description="编译代码">
<!-- 编译所有的Java代码 -->
<javac srcdir="${src.dir}"
destdir="${classes.dir}"
encoding="UTF-8"
includeantruntime="no"
excludes="**/test/*,**/test/bean/*,**/*.svn,*.svn"
includes="**/*.java"
source="1.6"
target="1.6"
deprecation="true"
failonerror="true"
debug="true">
<classpath refid="classpath" />
</javac>

<!-- 把所有文件copy到build目录 -->
<copy todir="${classes.dir}">
<fileset dir="${config.dir}/">
<exclude name="applicationContext.xml"></exclude>
<exclude name="log4j.properties"></exclude>
<exclude name="struts.properties"></exclude>
<exclude name="rebel.xml"></exclude>
<exclude name="zip.xml"></exclude>
<exclude name="pom_zip.xml"></exclude>
</fileset>
</copy>
</target>


<target name="5 - package" depends="4 - compile" description="打war包" >
<tstamp>
<format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss"/>
<format property="TIME" pattern="yyyyMMdd_HHmmss"/>
</tstamp>

<!-- copy资源和页面,以及生产配置文件 -->
<copy todir="${wars.dir}">

<fileset dir="${web.root}">
<exclude name="**/static/**"></exclude>
<exclude name="**/uploads/**"></exclude>

</fileset>

<fileset dir="${web.root}">
<include name="**/static/css/**/mobiscroll.css"/>
<include name="**/static/css/**/**.ttf"/>
<include name="**/static/css/**/**.woff"/>
<include name="**/static/js/**/**.json"/>
<include name="**/static/layui/**"/>
<include name="**/static/sbadmin/**"/>
<include name="**/static/udditor/**"/>
<include name="**/static/ueditor/**"/>
</fileset>

<fileset dir="${prod.config.dir}" includes="**/*"/>
</copy>


<echo message="生成版本号文件" />
<exec executable="version.bat" failonerror="false" dir="${wars.dir}"></exec>
<exec executable="vs.bat" failonerror="false" dir="${wars.dir}"></exec>

<!-- 生成Web配置及部署文件 -->
<jar jarfile="${dist.dir}/${project}_${TIME}.war">
<fileset dir="${wars.dir}">
<include name="**/*" />
</fileset>
</jar>
</target>


<target name="0 - default" depends="1 - clean, 5 - package">

</target>

</project>
*************感谢您的阅读*************