使用jenkins並發布應用到tomcat


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

 

1 . 創建項目

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

 

2. 配置構建步驟

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

 

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

 

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

  

  

 

點擊 立即構建 ,就可以看到構建成功了,打開網頁也可以看到項目了。

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

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

<?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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM