Linux下使用ant+svn发布java项目

来源:互联网 发布:水手服淘宝网 编辑:程序博客网 时间:2024/05/22 00:00

1. 下载ant http://ant.apache.org/bindownload.cgi

2. 解压到 /user/local

cd /usr/local  tar apache-ant-1.8.2-bin.zip

3. 设置环境变量

vi /etc/profile将ant_home加入环境变量中:export ANT_HOME=/usr/local/apache-ant-1.8.2export PATH=/usr/local/php/bin:$JAVA_HOME/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin:$ANT_HOME/bin:$PATH使环境变量生效:source /etc/profile

4. 检查

执行:ant -v可看到ant版本号说明安装成功

5. 配置ANTbuild.xml

注:
/data/wwwroot/xxxproject 改为你的项目所在目录
/usr/local/tomcat 改为你的tomcat所在目录
xxxproject 改成你的项目名

<?xml version="1.0" encoding="UTF-8"?><project name="xxxproject" default="deploy" basedir="/data/wwwroot/xxxproject">      <property environment="env" />      <property name="webapp.name" value="xxxproject"/>      <property name="catalina.home" value="/usr/local/tomcat" />      <property name="dist.dir" value="${basedir}/dist" />       <property name="webRoot.dir" value="${basedir}/WebRoot" />      <property name="src.dir" value="${basedir}/src" />      <property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" />      <property name="build.dir" value="${basedir}/build" />      <!-- 使用eclipse jdt进行编译,而不使用JDK编译  -->      <!-- 初始化classpath -->      <path id="project.classpath">          <fileset dir="${lib.dir}">              <include name="**/*.jar" />          </fileset>          <!-- 添加tomcat类路径 -->          <fileset dir="${catalina.home}/lib">              <include name="*.jar" />          </fileset>      </path>      <!-- get the source compile classpath in a printable form -->      <pathconvert pathsep="${line.separator}|   |-- "               property="echo.path.compile"               refid="project.classpath">      </pathconvert>      <!-- show classpath jars -->      <target name="print_classpath">          <echo message="|-- compile classpath"/>          <echo message="|   |"/>          <echo message="|   |-- ${echo.path.compile}"/>      </target>      <!-- 删除之前的目录结构 -->      <target name="clear" description="清理旧文件">          <delete dir="${build.dir}" />          <delete dir="${dist.dir}" />          <delete file="${catalina.home}/WebRoot/${webapp.name}.war" />          <delete dir="${catalina.home}/WebRoot/${webapp.name}" />      </target>      <!-- 创建目录结构 -->      <target name="init" depends="clear" description="创建初始化目录结构">          <mkdir dir="${build.dir}/classes" />          <mkdir dir="${dist.dir}" />      </target>      <!-- 编译java -->      <target name="compile" depends="init" description="编译java文件">          <echo message="begin compile..." />          <javac srcdir="${src.dir};${lib.dir}" destdir="${build.dir}/classes"               includeantruntime="false" nowarn="on"               source="1.6" target="1.6" deprecation="true" debug="true"               encoding="UTF-8" classpathref="project.classpath">            <compilerarg line="-Xlint:unchecked" />              <!-- <classpath refid="classpath" /> -->          </javac>          <copy todir="${build.dir}/classes">              <fileset dir="${src.dir}">                  <include name="**/*.xml" />                  <include name="**/*.properties" />                  <include name="**/*.sql" />              </fileset>           </copy>          <echo message="end compile..." />      </target>      <!-- 将class文件打成 jar包 -->      <!--            <target name="pack" depends="compile">               <jar jarfile="${build.dir}/${webapp.name}.jar">                   <fileset dir="${build.dir}/classes">                       <include name="**/*.class"/>                   </fileset>               </jar>           </target>       -->      <!-- 打成war包, 名称默认为 项目名 -->      <target name="war" depends="compile" description="将工程打成war包">          <echo message="begin war..." />          <war destfile="${dist.dir}/${webapp.name}.war" basedir="${webRoot.dir}"               webxml="${webRoot.dir}/WEB-INF/web.xml">              <lib dir="${lib.dir}" />              <classes dir="${build.dir}/classes" />              <fileset dir="${webRoot.dir}">                  <include name="***.*" />              </fileset>          </war>          <echo message="end war..." />      </target>      <!-- copy war包 tomcat的deploy目录 -->      <target name="deploy" depends="war" description="部署项目">          <echo message="begin deploy..." />          <copy file="${dist.dir}/${webapp.name}.war" todir="${catalina.home}/webapps" />          <echo message="end deploy..." />      </target></project>

6. 自动构建shell

vi build.shexport LANG=zh_CN.GB18030/usr/bin/svn checkout "svn://xxxxx/project/xxxxproject/cods" /data/wwwroot/xxxxproject/ --username=echo --password=123456chown www:www /data/wwwroot/xxxxproject/ -Rant -buildfile /data/wwwroot/xxxxproject/build.xmlchmod +x build.sh
0 0