使用jenkins併發布應用到tomcat

jenkins的介紹及安裝請自行百度,本文重點介紹如何使用jenkins,並自動發佈web應用到tomcat中.java

 

1 . 建立項目web

打開jenkins --> 新建 --> 填寫item名稱,就是項目名稱,這裏我選擇構建一個自由風格的軟件項目 -->保存shell

 

2. 配置構建步驟api

 在配置頁 --> ① 源碼管理 我用的svn,就選subversion了,填入項目的url , 首次使用jenkins須要配置svn帳號密碼,配置方法根據下方的提示。tomcat

 

   ② 構建觸發器 ,我這裏設置每小時構建一次eclipse

 

  ③ 配置構建步驟 , 這裏使用ant進行構建,選擇ant 版本-圖中選擇的是ant1.9.5 , 填寫tagets 這裏的main 即對應build.xml的main target ,這樣就會使用項目裏的              build.xml就行構建了。構建完了,須要將war包發佈到tomcat 裏, 再增長一個shell 步驟,ok.svn

  

  

 

點擊 當即構建 ,就能夠看到構建成功了,打開網頁也能夠看到項目了。ui

jenkins 使用比較簡單,關鍵在於配置ant build.xml ,以前沒有接觸過。web應用編譯須要servlet-api.jar ,考一個tomcat下的放到項目的lib下就能夠編譯經過了。url

附上build.xml 比較粗糙,(⊙﹏⊙)b:spa

<?xml version="1.0" encoding="utf-8"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. -->
<project basedir="." default="main" name="XX">
    <target name="main" depends="complie, compress" description="Main target">
       <echo>Building war file.</echo>
    </target>
    
    <property environment="env"/>
   
    <property name="debuglevel" value="source,lines,vars"/>
    
    <property name="target" value="1.7"/>
    <property name="source" value="1.7"/>
    
    <target name="init">
    <property name="build" value="build"></property>
    <property name="src" value="src"></property>
        <delete dir="${build}" />
        <mkdir dir="${build}"/>
        <mkdir dir="${build}\WEB-INF"/>
        <mkdir dir="${build}\WEB-INF\classes"/>
        <copy todir="${build}">
            <fileset dir="${basedir}\WebContent">
                <include name="WEB-INF/**" />
                <include name="META-INF/**" />
                <include name="api/**" />
                <include name="manage/**" />
            </fileset>
        </copy>
    </target>
    
    <!--定義項目編譯的時候,以來的lib包的路徑-->  
   <path id="project.class.path">  
       <!-- <pathelement path="${classpath}" /> -->  
       <fileset dir="${basedir}/WebContent/WEB-INF/lib">  
           <include name="**/*.jar" />  
       </fileset>  
   </path>
    
    <target name="complie" depends="init">
        <javac srcdir="${basedir}/src" destdir="${build}/WEB-INF/classes">
             <classpath refid="project.class.path" />  
        </javac>
        <copy todir="${build}/WEB-INF/classes">
            <fileset dir="${basedir}/src">
                <include name="**/**.xml" />
            </fileset>
        </copy>
    </target>
    
    <target name="compress" depends="complie">
        <war warfile="${build}/XX.war" webxml="${build}/WEB-INF/web.xml">
            <lib dir="${build}/WEB-INF/lib"/>
            <classes dir="${build}/WEB-INF/classes"/>
            <fileset dir="${build}"/>
        </war>
    </target>
     
</project>
相關文章
相關標籤/搜索