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

准备一个项目源码

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

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

1.git知识基础

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

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

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

2.Ant的build.xml文件

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

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

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

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(第三话):创建一个自由风格的项目(非maven),实现自动打war包

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

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

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

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

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

  4. jenkins之从0到1利用Git和Ant插件打war包并自动部署到tomcat(第二话):安装插件,配置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.XML文件(Jenkins可以参考)

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

  8. Jenkins+svn+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. 【linux下多实例Tomcat+Nginx+redis+mysql环境搭建】

    一.搭建环境之前最好自己先创建一个文件夹,再次文件夹下在创建文件夹来安放项目包和Tomcat等应用以及性能测试监控的文件 1.项目存放地址: mkdir export (创建一个文件),mkdir a ...

  2. log4j的基本使用方法

    本文转载自http://www.codeceo.com/article/log4j-usage.html 一.基本用法 1.log4j需要jar包log4j-1.2.14.jar,链接: http:/ ...

  3. topcoder srm 340 div1

    problem1 link $f[i][L][R]$表示计算到第$i$个,最小最大值是$L,R$时的最少个数. import java.util.*; import java.math.*; impo ...

  4. topcoder srm 699 div1 -3

    1.两个长度为$n$的数组$a,b$,$0 \leq a_{i} <2^{30}$.$b_{i}=-1$或者$b_{i}$为除$a_{i}$外其他数字的抑或值.现在给定$b$,如果不存在$a$, ...

  5. Python3基础 list list()生成空列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. 彻底了解 suid, sgid ,sticky权限

    sticky: 粘性的, 如 : sticky tape: 粘胶带 /tmp, /var/tmp: 位 sticky: 表示: 第一, 任何用户都可以在该目录下创建文件(编辑自己的文件),第二, 但是 ...

  7. IPVS负载均衡

    概念: ipvs (IP Virtual Server) 实现了传输层负载均衡,也就是我们常说的4层LAN交换,作为 Linux 内核的一部分.ipvs运行在主机上,在真实服务器集群前充当负载均衡器. ...

  8. Python hasattr() 函数 // python中hasattr()、getattr()、setattr()函数的使用

    http://www.runoob.com/python/python-func-hasattr.html https://www.cnblogs.com/zanjiahaoge666/p/74752 ...

  9. 论文笔记: Dual Deep Network for Visual Tracking

    论文笔记: Dual Deep Network for Visual Tracking  2017-10-17 21:57:08  先来看文章的流程吧 ... 可以看到,作者所总结的三个点在于: 1. ...

  10. mybatis配置文件namespace用法总结

    本文为博主原创,未经允许不得转载: 由于在应用过程中,发现namespace在配置文件中的重要性,以及配置的影响,在网上看了很多博客,发现很多人对namespace存在误解, 所以总结一下namesp ...