自动Build上传包到服务器

项目下的build.xml,可以自动build出war包和properties

*.war放置在jboss的deploy下,*.properties放置在conf下

build.xml文件如下:

<project name="MyProject" default="compile" basedir=".">
<!-- set global properties for this build -->
<property name="project" value="ehome"/>
<property name="src" location="src/java"/>
<property name="config" location="src/conf"/>
<property name="web" location="WebRoot"/>
<property name="web-lib" location="${web}/WEB-INF/lib"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>

<path id="classpath.compile">
       <fileset dir="${web-lib}">
         <include name="**/*.jar"/>
       </fileset>
       <pathelement path="${build}"/>
</path>
 
    <target name="init">
     <!-- Create the build directory structure used by compile -->
     <mkdir dir="${build}"/>
     <mkdir dir="${dist}"/>
</target>

<target name="compile" depends="init" description="compile the source" >
<mkdir dir="${build}/classes"/>
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}/classes" debug="true" deprecation="true" optimize="false" failonerror="true" encoding="utf-8">
     <classpath refid="classpath.compile"/>
    </javac>
</target>

<target name="copyWebFiles" depends="compile">
    <mkdir dir="${build}/web"/>
<copy todir="${build}/web">
   <fileset dir="${web}" excludes="WEB-INF/classes/">
   </fileset>
</copy>
<copy todir="${build}/web/WEB-INF/classes">
   <fileset dir="${build}/classes">
   </fileset>
   <fileset dir="${config}">
    <exclude name="**/*.properties"/>
    <exclude name="**/*.prod"/>
   </fileset>
</copy>
</target>

<target name="config4debug">
   <copy file="${config}/ehome.properties" tofile="${dist}/ehome.properties"/>
</target>

<target name="config4release">
   <copy file="${config}/ehome.properties.prod" tofile="${dist}/ehome.properties"/>
</target>

<target name="buildWar">
<mkdir dir="${dist}"/>
<war destfile="${dist}/${project}.war" webxml="${build}/web/WEB-INF/web.xml">
   <fileset dir="${build}/web"/>
</war>
</target>

<target name="jarWebServices">
   <jar destfile="${dist}/webservices-interface.jar" basedir="${build}/classes" includes="com/megaeyes/core/webservice/**" excludes="com/megaeyes/core/webservice/impl/**,com/megaeyes/core/webservice/transformer/**"/>
</target>

<target name="war" depends="clean,copyWebFiles,config4debug,buildWar" description="generate the war package for personal debug" >
</target>

<target name="release" depends="clean,copyWebFiles,config4release,buildWar" description="generate the war package for release" >
</target>

<target name="clean" description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
</target>

</project>

项目根上再写一个upload.bat文件,文件内容如下:

ftp -s:upload-test.txt

根目录上再写一个upload-test.txt文件,文件内容如下:

open 192.168.4.38
sillycat
kaishi

bin
put dist/*.war
put dist/*.properties
quit

这样

ant war

ant config4debug

upload.bat

就将本地项目打包上传到了服务器的/home/sillycat下。

再在服务器上运行build4debug.sh就可以将war和properties拷贝到JBOSS下面启动JBOSS

你可能感兴趣的:(xml,jboss,ant)