본문 바로가기

Dev. ProjectKICE/CI 서버 구축

Ant 빌드파일 작성

[출처] 인섬니아 블로그


Ant 빌드파일 작성

build.xml 파일 생성 : 웹용 ant 파일은 여기 참조

  • 프로젝트 컨텍스트 메뉴에서 New > File 선택
  • 파일명은 build.xml로 생성
  • Ctrl + Space 로 buildfile template 선택 : 기본 포맷 내용이 만들어짐

프로퍼티 지정

빌드시에 사용할 프로퍼티를 설정한다. 별도의 프로퍼티 파일로 생성해서 사용 가능

<!--퍼로퍼티 파일 지정 -->
 <property file="build.properties" />
  <!--퍼로퍼티 설정 : 각종 폴더 & 생성파일 -->
 <property name="project.name" value="VerySimpleBlog"/>
 <property name="base.dir" value="."/>
 <property name="src.dir" value="src" />
 <property name="web.dir" value="WebContent"/>
 <property name="dist.dir" value="dist"/>
 <property name="build.dir" value="build"/>
 <property name="war.file" value="${dist.dir}/${project.name}.war"/>

path 지정

컴파일에 필요한 라이브러리 패스를 설정한다.

 <!-- 컴파일 패스 설정 : 웹 라이브러리 위치 (WEB-INF/lib), 톰캣 라이브러리 추가(tomcat/lib) -->
 <path id="project.classpath">
  <pathelement location="${web.dir}/WEB-INF/lib"/>
  <fileset dir="${web.dir}/WEB-INF/lib">
   <include name="*.jar"/>
  </fileset>
  <pathelement location="${tomcat.home}/lib"/>
  <fileset dir="${tomcat.home}/lib">
   <include name="*.jar"/>
  </fileset>
 </path>

빌드 날짜 생성

빌드 날짜를 스탬프로 찍는다.

  <target name="datentime" description="create current date">
        <tstamp>
         <format property="DSTAMP" pattern="yyyy-MM-dd"/>
         <format property="TSTAMP" pattern="HH:mm:ss"/>
        </tstamp>
     <echo message="Build started at : ${DSTAMP} - ${TSTAMP}" />
    </target>

prepare

빌드하기전에 빌드폴더 생성 및 WebContent?내의 파일을 build 폴더로 복사한다.

 <target name="prepare" depends="datentime, clean" description="copy web contents">
        <mkdir dir="${build.dir}"/>
  <mkdir dir="${build.dir}/WEB-INF" />
  <mkdir dir="${build.dir}/WEB-INF/classes" />
  <copy todir="${build.dir}">
   <fileset dir="${web.dir}" />
  </copy>
    </target>

Clean

build와 dist 폴더를 삭제한다.

   <target name="clean" description="delete build, dist">
        <delete dir="${dist.dir}" />
        <delete dir="${build.dir}" />
    </target>

build

build 폴더에 자바 컴파일 후 classes 파일을 복사한다.

<target name="build" depends="prepare" description="compile java">
     <javac srcdir="${src.dir}"
        destdir="${build.dir}/WEB-INF/classes"
        debug="${compile.debug}"
        deprecation="${compile.deprecation}"
        optimize="${compile.optimize}"
        classpathref="project.classpath">
  </javac>
     <copy todir="${build.dir}/WEB-INF/classes">
      <fileset dir="${src.dir}" excludes="**/*.java, **/*.properties" />
     </copy>
  </target>

Dist

build 폴더를 프로젝트이름.war로 압축해서 dist 폴더로

 <target name="dist" depends="build" description="make war file from build to dist">
     <mkdir dir="${dist.dir}"/>       
     <jar destfile="${war.file}" basedir="${build.dir}" />
    </target>

apply

build 폴더와 톰캣 app 폴더와 동기화 시킨다.

<target name="apply" depends="build" description="sync between webapp and build ">
     <sync todir="${tomcat.home}/webapps/${project.name}">
   <fileset dir="${build.dir}" />
  </sync>
</target>

javadoc

api documentation 생성

 <target name="javadoc" description="api documentation">
  <mkdir dir="${dist.dir}/docs/api" />
  <javadoc sourcepath="${src.dir}" destdir="${dist.dir}/docs/api" packagenames="*">
   <classpath refid="project.classpath" />
  </javadoc>
 </target>