본문 바로가기
FullStack/41. WEB.WAS

Ant로 컴파일 및 Tomcat 서버 배포

by nakanara 2012. 3. 16.
반응형

 

얼마 프로젝트 사용한 ant 배포 파일입니다.

Maven 으로 처리하고 싶었지만 maven 대한 사전지식이 부족하여 ant 뚝딱뚝딱.

Ant 컴파일, tomcat 배포, 등등의 기능이 포함되어 있습니다.
 

Build.properties

###############################################################################

# ant 배포 설정파일 

#

#             2012. nakanara

###############################################################################


# Application Name

name=nakanara


###############################################################################

was.dir=c:/Tomcat6


was.deploy.dir=c:/Tomcat6/webapps


#report

report.dir=report


Build.xml

<?xml version="1.0"?>


<project name="ITSM" default="init" basedir=".">

        

  <!-- Import file -->    

  <property file="build.properties"/>


  <property name="java.src.dir" value="src/main/java" />

  <property name="java.test.dir" value="src/test/java" />

  <property name="java.test.lib" value="src/test/lib" />

  <property name="java.res.dir" value="src/main/resource" />

  <property name="web.dir" value="WebContent" />


  <property name="build.dir" value="${web.dir}/WEB-INF/classes" />


  <echo message="${name} Build"/>


  <path id="dev.classpath">

      <fileset dir="${web.dir}/WEB-INF/lib">

        <include name="*.jar" />

      </fileset>

      <fileset dir="${was.dir}/lib">

        <include name="*.jar" />

      </fileset>

      <pathelement path="${build.dir}" />

  </path>


  <!-- Target Define -->

  <target name="usage" description="Ant Build Usage">

      <echo message="" />

      <echo message="${name} build file" />

      <echo message="-----------------------------------" />

      <echo message="" />

      <echo message="Available targets are:" />

      <echo message="Compile" />

      <echo message="compile.java               --> Compile Java Files" />

      <echo message="dev.deploy                 --> Deploy to Development Machine" />

      <echo message="" />

      <echo message="appserver.deploy           --> Deploy to Operational Machine" />

      <echo message="" />

      <echo message="clean                      --> Clean Output Folder" />

      <echo message="" />

  </target>

  

  <target name="init">

    <echo message="Init Ant" /> 

  </target>


  <!-- 

  http://funiphone.tistory.com/15

    한글 주석의 경우로 인해 warning: unmappable character for encoding UTF-8 

    윈도우 환경에서 java로 개발하고 컴파일 했을때 이상없던 소스가 리눅스 환경에서 컴파일 하면 

  warning: unmappable character for encoding UTF-8 같은 warning이 발생하는 경우가 있습니다. 

    대부분이 javadoc을 위한 한글 주석에서 원인이 발생하고 있습니다.

    현재 제가 개발하는 환경은 Eclipse를 통해 여러명이서 로컬로 개발을 하고 CVS 서버로 commit해서 테스트 서버가 변경된 소스를 확인해 compile 및 test를 자동 수행하고 있습니다. 

    이때 Eclipse에서는 문제 없던 소스가 테스트 서버에서 compile하게 되면 위와 같은 warning을 메일로 보내고 있어 다음과 같이 해결했습니다.

  -->

      

  <!--

  Recompile with -Xlint:deprecation for details.

    경고가 뜨는 부분이 어딘지 알려면 -Xlint:unchecked 옵션을 주어서 컴파일을 해야 되는데.. 

    그냥 콘솔에서 컴파일 할때에는 javac -Xlint:unchecked .. 하고 넣어주면 된다.

    1.6버전서 부터는 제네릭 타입으로 선언을 해야만 컴파일시 -Xlint:unchecked오류가 안난다.

  -->

  

  <target name="compile.java.test" depends="" description="Compile test">

      <mkdir dir="${build.dir}" />   

      <javac srcdir="${java.src.dir}" destdir="${build.dir}"

           includes="com/nakanara/test/**/*.java" debug="true" includeantruntime="false">

        <classpath refid="dev.classpath" />

        <compilerarg value="-Xlint:unchecked"/>

      </javac>   

  </target>


  <target name="compile.java.test2" depends="compile.java.test" description="Compile test2">

      <mkdir dir="${build.dir}" />     

      <javac srcdir="${java.src.dir}" destdir="${build.dir}"

          encoding="UTF-8" includes="com/nakanara/test2/**/*.java" debug="false" includeantruntime="false">

        <classpath refid="dev.classpath" />

        <compilerarg value="-Xlint:unchecked"/>

      </javac>   

  </target> 


  

  <target name="compile.java" depends="compile.java.test, compile.java.test2" description="Compile test, test2">    

  </target> 


  <!--

  Resource Copy.

  -->

  <target name="copy.res" description="Copy Resource">

      <copy todir="${build.dir}">

        <fileset dir="${java.src.dir}">

            <include name="**/*.xml"/>

        </fileset>

        <fileset dir="${java.res.dir}">

            <include name="**/*.*"/>          

        </fileset>

      </copy>  

  </target> 

  

  

  <target name="dev.deploy" description="DeveloperServ Deploy">

    <echo>Deploy ${was.deploy.dir}/${name}</echo>

    <sync todir="${was.deploy.dir}/${name}">

      <fileset dir="${web.dir}">

          <include name="**/*.*"/>

          <exclude name="${report.dir}/*.*"/>

          <exclude name="com/nakanara/**/sys/*TEST.*" />

      </fileset>

        

    </sync>

  </target>

  

  <!--

  http://finkle.tistory.com/71

  ANT 빌드 스크립트에서 아래와 같이 Tomcat 재기동 작업을 설정 후 Hudson에 연결했을 경우 생성되는 Hudosn 하위 프로세스가 종료되지 않고 대기하는 문제가 발생한다.

  spawn :  하위 프로세스를 생성해서 실행하는 옵션

  --> 

  <target name="was.start">

    <echo message="Start Tomcat" />

    <java dir="${was.dir}/bin/" jar="${was.dir}/bin/bootstrap.jar" fork="true" spawn="true">        

      <jvmarg value="-Dcatalina.home=${was.dir}"/>

      <arg value="start"/>   

    </java>

    <sleep seconds="5" />

    <echo message="Start Tomcat success" />

  </target>

  

  <target name="was.stop">

    <echo message="Stop Tomcat" />  

    <java dir="${was.dir}/bin/" jar="${was.dir}/bin/bootstrap.jar" fork="true">

      <jvmarg value="-Dcatalina.home=${was.dir}"/>

      <arg value="stop"/>   

    </java>

    <echo message="Stop Tomcat success" />

  </target>


  <!-- haltonfailure: 실패할 경우 전체 불합격. -->

  <!--http://ant.apache.org/manual/Tasks/junit.html -->

  <target name="Junit.Test" description="Junit Test">

      <echo message="Junit Test Report : ${web.dir}/${report.dir}" />

      <echo message="Build Dir : ${build.dir}" />

      

      <mkdir dir="${web.dir}/${report.dir}"/>

      <delete>

          <fileset dir="${web.dir}/${report.dir}"></fileset>

      </delete>

        

            

      <junit fork="no" printsummary="true" haltonfailure="false" haltonerror="false" description="Junit Test">      

          <classpath refid="dev.classpath"/>

          <classpath path="${build.dir}" />

             

          <formatter type="xml"/>

          <batchtest fork="yes" errorproperty="true" failureproperty="true" todir="${web.dir}/${report.dir}">

              <fileset dir="${java.test.dir}" includes="com/nakanara/**/sys/*Test.java"></fileset>                

          </batchtest>

      </junit>

      

      

      <!--보고서 생성 -->

      <junitreport todir="${web.dir}/${report.dir}">

          <fileset dir="${web.dir}/${report.dir}">

                <include name="*.xml"/>

          </fileset>

          <report format="frames" todir="${web.dir}/${report.dir}/html"/>        

      </junitreport>    

  </target>

  

  <target name="clean" description="Clear BuildDir, DeployDir.">

      <echo>Delete ${build.dir}</echo>

      <echo>Delete ${was.deploy.dir}/${name}</echo>

      <delete dir="${build.dir}"></delete>

      <delete dir="${was.deploy.dir}/${name}"></delete>

  </target>

  

  


  <!--############################################

  Check Style

  ################################################ -->

  

  <target name="checkstyle">        

      <checkstyle config="${java.test.lib}/sun_chkecks.xml"

          failureProperty="checkstyle.fail"

          failOnViolation="false">

          

          <classpath>

              <path refid="dev.classpath" />

              <fileset dir="${java.test.lib}" includes="**/*.jar"></fileset>

          </classpath>

          

          <formatter type="xml" tofile="${web.dir}/${report.dir}/checkstyle_report.xml" />

          <fileset dir="${java.src.dir}" includes="com/nakanara/**.*.*"/>

      </checkstyle>

      

      <style in="${web.dir}/${report.dir}/checkstyle_report.xml" 

          out="${web.dir}/${report.dir}/checkstyle_report.html" 

          style="checkstyle.xsl">

      </style>        

  </target>

  

  <target name="checkstyle-nightly" depends="checkstyle" if="checkstyle.fail" description="CheckStyle Fail">

    <mail from="nakanara@nakanara.com" tolist="nakanara@nakanara.com" 

        mailhost="smtp.gmail.com" charset="UTF-8" ssl="true" mailport="465" 

        id="nakanara@nakanara.com" password="1234"

        subject="스타일체크 결과입니다." files="${web.dir}/${report.dir}/checkstyle_report.html">         

    </mail>

  </target>

  


</project>


반응형