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

准备一个项目源码

刚开始在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. Python学习基础(三)——装饰器,列表生成器,斐波那契数列

    装饰器——闭包 # 装饰器 闭包 ''' 如果一个内部函数对外部(非全局)的变量进行了引用,那么内部函数被认为是闭包 闭包 = 函数块 + 定义时的函数环境 ''' def f(): x = 100 ...

  2. 【python35.1--EasyGui界面】

    一.什么是EasyGUI EasyGUI是python中一个非常简单的GUI编程模块,不同于其他的GUI生成器,它不是事件驱动的,相反,所有的GUI交互都是通过简地函数调用就可以实现(意思是:函数调用 ...

  3. CXF整合spring,在tomcat中发布webService

    服务端 1.首先下载CXF的jar包 http://pan.baidu.com/s/1dFBwSRf 密码: qyax.里面自带了需要用到的spring的jar包. 或者使用maven,如下配置.不论 ...

  4. Bootstrap3基础 input-group glyphicon 输入框组与glyphicon图标

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  5. 通过SIMPLE_DEV_PM_OPS定义suspend和resume函数【转】

    本文转载自:https://blog.csdn.net/tiantao2012/article/details/77851782 通过SIMPLE_DEV_PM_OPS 定义这个驱动的suspend和 ...

  6. 修改sepolicy后编译出现‘Error while expanding policy’【转】

    本文转载自:https://blog.csdn.net/yin1031468524/article/details/75644874 在系统中添加某个“*.te”后,可能会出现下面的错误: libse ...

  7. linux下如何使make只输出执行过程中的命令序列

    答: make -n (-n.--just-print.--dry-run.--recon等价)

  8. docker版本升级

    docker的版本变化: Docker从1.13.x版本开始,版本分为企业版EE和社区版CE,版本号也改为按照时间线来发布,比如17.03就是2017年3月,有点类似于ubuntu的版本发布方式. 企 ...

  9. docker-compose安装与部署项目

    安装: 1.curl安装慢的问题 解决:改用pip安装,需要先安装pip相关,参照: https://www.cnblogs.com/YatHo/p/7815400.html 2.pip安装依赖库re ...

  10. Concepts-->Migrations

    https://flywaydb.org/documentation/migrations Overview With Flyway all changes to the database are c ...