jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第五话):总结以及build.xml文件

时间:2022-12-20 22:58:31

前面基本上把整个配置过程都完整地串起来了,包括可能遇到的难点,按照那个套路应该可以配置好自动打包发布的功能。简单总结下我的学习过程,以及遇到问题是怎样解决的。

准备一个项目源码

刚开始在github和码云上搜索有没有现成的练习项目,很可惜,没有找到,所以只能自己创建一个简单的项目,当然,如果在公司有源码浏览权限的话可以直接使用公司git服务器上的项目来练习,可惜我们公司并没有给测试人员开放源码权限。

我特意下载了一个Intellij IDEA来新建java工程(呵呵,杀鸡用牛刀~~),Ant的build.xml文件也是用Intellij IDEA来生成的,只需做一些小改动就能用。

1.git知识基础

因为没有公司源码权限,所以需要借助github或者码云来管理这个HelloWorld项目,用码云托管项目倒没有花费我太多时间,因为刚好前一段时间学习了git的基本操作,很顺利地就把源码push到了码云上面。

学会使用git的话,也可以在后面验证jenkins是否真的自动部署了,可以在本地git仓库把程序代码改动一下,然后push到远程仓库,在jenkins构建一下,再访问HelloWorld看看是否发生变化

jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第五话):总结以及build.xml文件

jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第五话):总结以及build.xml文件

可以看到新构建的任务changes那里显示便是git commit提交时加的注释(附:廖雪峰git教程地址

2.Ant的build.xml文件

这里也花了很多时间,其实到现在也还没完全了解,感兴趣的小伙伴可以看看:ant教程(不过据说现在用ant打包的比较少了,都在用maven了,jenkins也可以构建maven项目的,不过我还没研究)

利用Ant打包时,注意指定target,target表示是一个个的待执行的任务,例如我在本地打包时

jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第五话):总结以及build.xml文件

build.xml文件一般放在java项目的工程目录的最外层(当然文件中具体定义的相对路径有关)

jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第五话):总结以及build.xml文件

jenkins做的其实就是调用Ant,然后利用build.xml文件实现打包功能

我用的build.xml内容如下:

  <property file="build.properties"/>
<!-- Uncomment the following property if no tests compilation is needed -->
<!--
<property name="skip.tests" value="true"/>
--> <!-- Compiler options --> <property name="compiler.debug" value="on"/>
<property name="compiler.generate.no.warnings" value="off"/>
<property name="compiler.args" value=""/>
<property name="compiler.max.memory" value="700m"/>
<patternset id="ignored.files">
<exclude name="**/*.hprof/**"/>
<exclude name="**/*.pyc/**"/>
<exclude name="**/*.pyo/**"/>
<exclude name="**/*.rbc/**"/>
<exclude name="**/*.yarb/**"/>
<exclude name="**/*~/**"/>
<exclude name="**/.DS_Store/**"/>
<exclude name="**/.git/**"/>
<exclude name="**/.hg/**"/>
<exclude name="**/.svn/**"/>
<exclude name="**/CVS/**"/>
<exclude name="**/__pycache__/**"/>
<exclude name="**/_svn/**"/>
<exclude name="**/vssver.scc/**"/>
<exclude name="**/vssver2.scc/**"/>
</patternset>
<patternset id="library.patterns">
<include name="*.egg"/>
<include name="*.jar"/>
<include name="*.ear"/>
<include name="*.swc"/>
<include name="*.war"/>
<include name="*.zip"/>
<include name="*.ane"/>
</patternset>
<patternset id="compiler.resources">
<exclude name="**/?*.java"/>
<exclude name="**/?*.form"/>
<exclude name="**/?*.class"/>
<exclude name="**/?*.groovy"/>
<exclude name="**/?*.scala"/>
<exclude name="**/?*.flex"/>
<exclude name="**/?*.kt"/>
<exclude name="**/?*.clj"/>
<exclude name="**/?*.aj"/>
</patternset> <!-- JDK definitions --> <property name="jdk.bin.1.7" value="${jdk.home.1.7}/bin"/>
<path id="jdk.classpath.1.7">
<fileset dir="${jdk.home.1.7}">
<include name="jre/lib/charsets.jar"/>
<include name="jre/lib/deploy.jar"/>
<include name="jre/lib/ext/access-bridge-64.jar"/>
<include name="jre/lib/ext/dnsns.jar"/>
<include name="jre/lib/ext/jaccess.jar"/>
<include name="jre/lib/ext/localedata.jar"/>
<include name="jre/lib/ext/sunec.jar"/>
<include name="jre/lib/ext/sunjce_provider.jar"/>
<include name="jre/lib/ext/sunmscapi.jar"/>
<include name="jre/lib/ext/zipfs.jar"/>
<include name="jre/lib/javaws.jar"/>
<include name="jre/lib/jce.jar"/>
<include name="jre/lib/jfr.jar"/>
<include name="jre/lib/jfxrt.jar"/>
<include name="jre/lib/jsse.jar"/>
<include name="jre/lib/management-agent.jar"/>
<include name="jre/lib/plugin.jar"/>
<include name="jre/lib/resources.jar"/>
<include name="jre/lib/rt.jar"/>
</fileset>
</path> <property name="project.jdk.home" value="${jdk.home.1.7}"/>
<property name="project.jdk.bin" value="${jdk.bin.1.7}"/>
<property name="project.jdk.classpath" value="jdk.classpath.1.7"/> <!-- Application Server Libraries -->
<!-- Register Custom Compiler Taskdefs -->
<property name="javac2.home" value="${idea.home}/lib"/>
<path id="javac2.classpath">
<fileset dir="${javac2.home}">
<include name="javac2.jar"/>
<include name="jdom.jar"/>
<include name="asm-all*.jar"/>
<include name="jgoodies-forms.jar"/>
</fileset>
</path>
<target name="register.custom.compilers">
<taskdef name="javac2" classname="com.intellij.ant.Javac2" classpathref="javac2.classpath"/>
<taskdef name="instrumentIdeaExtensions" classname="com.intellij.ant.InstrumentIdeaExtensions" classpathref="javac2.classpath"/>
</target> <!-- Modules --> <!-- Module HelloWorld --> <dirname property="module.HelloWorld.basedir" file="${ant.file}"/> <property name="module.jdk.home.HelloWorld" value="${project.jdk.home}"/>
<property name="module.jdk.bin.HelloWorld" value="${project.jdk.bin}"/>
<property name="module.jdk.classpath.HelloWorld" value="${project.jdk.classpath}"/> <property name="compiler.args.HelloWorld" value="-encoding UTF-8 -source 7 -target 7 ${compiler.args}"/> <property name="HelloWorld.output.dir" value="${module.HelloWorld.basedir}/web/WEB-INF/classes"/>
<property name="HelloWorld.testoutput.dir" value="${module.HelloWorld.basedir}/web/WEB-INF/classes"/> <path id="HelloWorld.module.bootclasspath">
<!-- Paths to be included in compilation bootclasspath -->
</path> <path id="HelloWorld.module.production.classpath">
<path refid="${module.jdk.classpath.HelloWorld}"/>
<fileset dir="${basedir}/web/WEB-INF/lib">
<patternset refid="library.patterns"/>
</fileset>
</path> <path id="HelloWorld.runtime.production.module.classpath">
<pathelement location="${HelloWorld.output.dir}"/>
<fileset dir="${basedir}/web/WEB-INF/lib">
<patternset refid="library.patterns"/>
</fileset>
</path> <path id="HelloWorld.module.classpath">
<path refid="${module.jdk.classpath.HelloWorld}"/>
<pathelement location="${HelloWorld.output.dir}"/>
<fileset dir="${basedir}/web/WEB-INF/lib">
<patternset refid="library.patterns"/>
</fileset>
</path> <path id="HelloWorld.runtime.module.classpath">
<pathelement location="${HelloWorld.output.dir}"/>
<fileset dir="${basedir}/web/WEB-INF/lib">
<patternset refid="library.patterns"/>
</fileset>
</path> <patternset id="excluded.from.module.HelloWorld">
<patternset refid="ignored.files"/>
</patternset> <patternset id="excluded.from.compilation.HelloWorld">
<patternset refid="excluded.from.module.HelloWorld"/>
</patternset> <path id="HelloWorld.module.sourcepath">
<dirset dir="${module.HelloWorld.basedir}">
<include name="src"/>
</dirset>
</path> <target name="compile.module.HelloWorld" depends="compile.module.HelloWorld.production,compile.module.HelloWorld.tests" description="Compile module HelloWorld"/> <target name="compile.module.HelloWorld.production" depends="register.custom.compilers" description="Compile module HelloWorld; production classes">
<mkdir dir="${HelloWorld.output.dir}"/>
<javac2 destdir="${HelloWorld.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.HelloWorld}/javac">
<compilerarg line="${compiler.args.HelloWorld}"/>
<bootclasspath refid="HelloWorld.module.bootclasspath"/>
<classpath refid="HelloWorld.module.production.classpath"/>
<src refid="HelloWorld.module.sourcepath"/>
<patternset refid="excluded.from.compilation.HelloWorld"/>
</javac2> <copy todir="${HelloWorld.output.dir}">
<fileset dir="${module.HelloWorld.basedir}/src">
<patternset refid="compiler.resources"/>
<type type="file"/>
</fileset>
</copy>
</target> <target name="compile.module.HelloWorld.tests" depends="register.custom.compilers,compile.module.HelloWorld.production" description="compile module HelloWorld; test classes" unless="skip.tests"/> <target name="clean.module.HelloWorld" description="cleanup module">
<delete dir="${HelloWorld.output.dir}"/>
<delete dir="${HelloWorld.testoutput.dir}"/>
</target> <target name="init" description="Build initialization">
<!-- Perform any build initialization in this target -->
</target> <target name="clean" depends="clean.module.HelloWorld, clean.artifact.HelloWorld:war_exploded" description="cleanup all"/> <target name="build.modules" depends="init, clean, compile.module.HelloWorld" description="build all modules"/> <target name="init.artifacts">
<property name="artifacts.temp.dir" value="${basedir}/output"/>
<property name="artifact.output.helloworld" value="${basedir}/out/artifacts/helloworld"/>
<property name="artifact.output.HelloWorld:war" value="${basedir}/out/artifacts/HelloWorld_war"/>
<property name="artifact.output.HelloWorld:war_exploded" value="${basedir}/out/artifacts/HelloWorld_war_exploded"/>
<mkdir dir="${artifacts.temp.dir}"/>
<property name="temp.jar.path.helloworld.war" value="${artifacts.temp.dir}/helloworld.war"/>
<property name="temp.jar.path.HelloWorld_war.war" value="${artifacts.temp.dir}/HelloWorld_war.war"/>
</target> <target name="clean.artifact.HelloWorld:war_exploded" description="clean HelloWorld:war exploded artifact output">
<delete dir="${artifact.output.HelloWorld:war_exploded}"/>
</target> <target name="artifact.helloworld" depends="init.artifacts" description="Build 'helloworld' artifact">
<property name="artifact.temp.output.helloworld" value="${artifacts.temp.dir}/helloworld"/>
<!--mkdir dir="${artifact.temp.output.helloworld}"/-->
<war destfile="${temp.jar.path.helloworld.war}">
<zipfileset dir="${basedir}/web"/>
</war>
<!--copy file="${temp.jar.path.helloworld.war}" tofile="${artifact.temp.output.helloworld}/helloworld.war"/-->
</target> <!--target name="artifact.HelloWorld:war" depends="init.artifacts, artifact.HelloWorld:war_exploded" description="Build 'HelloWorld:war' artifact">
<property name="artifact.temp.output.HelloWorld:war" value="${artifacts.temp.dir}/HelloWorld_war"/>
<mkdir dir="${artifact.temp.output.HelloWorld:war}"/>
<war destfile="${temp.jar.path.HelloWorld_war.war}">
<zipfileset dir="${artifact.output.HelloWorld:war_exploded}"/>
</war>
<copy file="${temp.jar.path.HelloWorld_war.war}" tofile="${artifact.temp.output.HelloWorld:war}/HelloWorld_war.war"/>
</target--> <!--target name="artifact.HelloWorld:war_exploded" depends="init.artifacts, compile.module.HelloWorld" description="Build 'HelloWorld:war exploded' artifact">
<mkdir dir="${artifact.output.HelloWorld:war_exploded}"/>
<copy todir="${artifact.output.HelloWorld:war_exploded}">
<fileset dir="${basedir}/web"/>
</copy>
<mkdir dir="${artifact.output.HelloWorld:war_exploded}/WEB-INF"/>
<copy file="${basedir}/web/WEB-INF/web.xml" tofile="${artifact.output.HelloWorld:war_exploded}/WEB-INF/web.xml"/>
<mkdir dir="${artifact.output.HelloWorld:war_exploded}/WEB-INF"/>
<mkdir dir="${artifact.output.HelloWorld:war_exploded}/WEB-INF/classes"/>
<copy todir="${artifact.output.HelloWorld:war_exploded}/WEB-INF/classes">
<fileset dir="${HelloWorld.output.dir}"/>
</copy>
</target--> <target name="build.all.artifacts" depends="artifact.helloworld" description="Build all artifacts">
<mkdir dir="${artifact.output.helloworld}"/>
<copy todir="${artifact.output.helloworld}">
<fileset dir="${artifact.temp.output.helloworld}"/>
</copy>
<mkdir dir="${artifact.output.HelloWorld:war}"/>
<copy todir="${artifact.output.HelloWorld:war}">
<fileset dir="${artifact.temp.output.HelloWorld:war}"/>
</copy> <!-- Delete temporary files -->
<delete dir="${artifacts.temp.dir}"/>
</target> <target name="all" depends="build.modules, build.all.artifacts" description="build all"/>
</project>

jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第五话):总结以及build.xml文件的更多相关文章

  1. jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat&lpar;第三话&rpar;:创建一个*风格的项目(非maven),实现自动打war包

    上一节把git和ant安装在虚拟机,并在jenkins上做了相关配置,接下来就可以真正开始构建一个项目了 1.新建一个*风格的项目,因为是用ant打包,所以不要选择构建maven项目 2.配置源码管 ...

  2. jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat&lpar;第四话&rpar;:把war包远程部署到tomcat

    上一节介绍了如何用Ant插件来打war包,本节接着介绍如何把build好的war自动部署到tomcat中 1.先安装 Deploy to container Plugin插件 2. 在构建后操作中添加 ...

  3. jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat&lpar;第一话&rpar;:初次启动jenkins,输入给定密码后登录失败问题解决

    Jenkins是一个持续集成平台,它能够从git等源码管理服务器拉取代码.打包并发布到tomcat等中间件,只要配置好相关插件,就可以做到项目的自动化构建.部署,不论是对开发来说监控代码质量,还是对测 ...

  4. jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat&lpar;第二话&rpar;:安装插件,配置JDK、Git、Ant

    jenkins之所以这么强大,离不开丰富的插件库. 要确保jenkins上安装好Git plugin.GitHub plugin.AntPlugin插件,一般在启动jenkins时默认安装的插件中就包 ...

  5. Jenkins自动打war包,并部署到tomcat服务器

    由于每次修改完代码,都要手动打包部署,很麻烦.今天研究了一下Jenkins自动化部署,大概有以下几个步骤: 1.先配置tomcat 7的访问用户和密码.文件位于conf/tomcat-users.xm ...

  6. docker:(5)利用docker -v 和 Publish over SSH插件实现war包自动部署到docker

    在 docker:(3)docker容器挂载宿主主机目录 中介绍了运行docker时的一个重要命令 -v sudo docker run -p : --name tomcat_xiao_volume ...

  7. 一个完整的JENKINS下的ANT BUILD&period;XML文件&lpar;Jenkins可以参考&rpar;

    一个完整的JENKINS下的ANT BUILD.XML文件 <?xml version="1.0" encoding="UTF-8"?> <p ...

  8. Jenkins&plus;svn&plus;maven自动部署到tomcat

    jenkins所在主机配置好,jdk,maven,Tomcat 1.配置maven,jdk环境 1) 进入配置界面--->[系统管理]--->[Global Tool Configurat ...

  9. 利用MyEclipse的ant插件生成Hibernate的映射文件

    先下载:xdoclet-plugins-dist-1.0.4-bin build.xml文件 <?xml version="1.0" encoding="UTF-8 ...

随机推荐

  1. Memcached初识

    高性能分布式内存对象缓存系统. 参考: Memcached官网: Memcached简介-1:Memcached简介-2: Memcached 教程 | 菜鸟教程:

  2. oneThink安装出错解决

    在Wampserver3.0.0(apache2.4.17+php5.6.15+mysql5.7.9)版本中oneThink安装用1.1github版,不要用1.1开发版,不然安装的时候数据库导入时b ...

  3. 介绍几种大型的Oracle&sol;SQL Server数据库免费版

    我们知道,Oracle和SQL Server等大型数据库也都存在一些免费的版本,这些免费的版本已经能够满足许多中小项目的需求.对于在校大学生来说,从学习的目标上来讲,安装免费版的大型数据库也就足够用了 ...

  4. YII框架路由和URL生成

    路由和URL生成 当一个YII应用开始处理一个请求的时候,它首先要做的便是将请求的URL转化成一个路由.路由的作用是用于后续实例化相应的控制器和操作,以便处理请求,整个处理过程便叫做路由.路由的逆过程 ...

  5. Ubuntu安装JDK&lpar;tar&period;gz&rpar;

    如果没有创建root用户: sudo passwd root 在oracle官网下载jdk(百度"JDK")的tar.gz包: jdk-7u55-linux-x64.gz 这是我下 ...

  6. 2017最新技术java高级架构、千万高并发、分布式集群、架构师入门到精通视频教程

    * { font-family: "Microsoft YaHei" !important } h1 { color: #FF0 } 15套java架构师.集群.高可用.高可扩展. ...

  7. openCV使用

    三方框架----> oprnCV使用的步骤 第一步:从官网下载framework添加到工程 1.打开 http://opencv.org/ 2. 3. 4. 3执行完之后 新打开的网页会倒计时为 ...

  8. 无依赖简单易用的Dynamics 365公共视图克隆工具

    本人微信公众号:微软动态CRM专家罗勇 ,回复279或者20180818可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . Dy ...

  9. CAS单点登录--转载

    一:单点登录介绍 单点登录( Single Sign-On , 简称 SSO )是目前比较流行的服务于企业业务整合的解决方案之一, SSO 使得在多个应用系统中,用户只需要 登录一次 就可以访问所有相 ...

  10. linux PWM蜂鸣器移植以及驱动程序分析【转】

    本文转载自:https://blog.csdn.net/lxllinux/article/details/80885331 一.关于PWM:        PWM(Pulse Width Modula ...