当前位置: 代码迷 >> J2EE >> ~请教大家,还有人用~ANT~给JAVA工程或WEB工程打包的吗?
  详细解决方案

~请教大家,还有人用~ANT~给JAVA工程或WEB工程打包的吗?

热度:839   发布时间:2016-04-22 00:33:44.0
~~~~~~请问大家,还有人用~~~~ANT~~~给JAVA工程或WEB工程打包的吗?~~~~~~
~~~~~~请问大家,还有人用~~~~ANT~~~给JAVA工程或WEB工程打包的吗?~~~~~~

在好几年前,我常见有前辈用ant打包。
但是现在越来越少有人用ant了。 

想请教一下,ant的详细配置,以及ant的优势和缺点。 请高手指教!

本人CSDN博客 http://blog.csdn.net/yjflinchong

------解决方案--------------------
同问....mark一下.
------解决方案--------------------
我们公司就是用ant,生成struts hibernate和webservice的配置文件和包。不过脚本不是我写的,我也没看。
------解决方案--------------------
搂主 若问的太详细不如google 若有个别疑问 可以提出来 

我公司的项目就是用ant打包
------解决方案--------------------
网上有ant教程的,我用过它来打包web项目(编译、打包、部署、发布。。。。)对工程制动化发布。
------解决方案--------------------
ant教程,网上应该有很多的
------解决方案--------------------
这是我们项目的build.xml,我只知道双击它就可以自动运行,但是具体脚本的意思我没看过。。不好意思太长了,我只能截一部分。。

XML code
    <!-- import properties (app settings, classpath, jar file locations) -->    <import file="properties.xml"/>    <target name="init" description="defines custom tasks">        <!-- Taskdefs -->        <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${ant-contrib.jar}"/>                <!-- Ensure that Ant 1.6.2+ is being used -->        <available classname="org.apache.tools.ant.DynamicAttribute" property="ant-1.6.2"/>        <fail unless="ant-1.6.2" message="AppFuse requires Ant 1.6.2 for faster unit testing"/>                 <!-- Conditionally set property for tomcat -->        <condition property="server.use.tomcat">            <equals arg1="${server.type}" arg2="tomcat"/>        </condition>                <condition property="server.use.jboss">            <equals arg1="${server.type}" arg2="jboss"/>        </condition>    </target>        <!-- Check timestamp on files -->    <target name="prepare" depends="init" description="create target directories">        <tstamp/>        <tstamp><format property="copyright.year" pattern="yyyy"/></tstamp>        <echo message="Preparing target directory '${webapp.target}'"/>        <mkdir dir="${webapp.target}"/>        <mkdir dir="${webapp.dist}"/>        <mkdir dir="${web.classes.dir}"/>                <mkdir dir="${build.dir}/resources"/>        <mkdir dir="${build.dir}/dao/gen"/>        <mkdir dir="${build.dir}/web/gen"/>        <!-- Make sure hibernatedoclet is necessary -->        <uptodate property="hibernatedoclet.unnecessary">            <srcfiles dir="src/dao" includes="**/*.java"/>            <srcfiles dir="${build.dir}/dao/gen" includes="**/*.java"/>            <mapper type="glob" from="*.java" to="${build.dir}/dao/classes/*.class"/>        </uptodate>        <!-- Make sure webdoclet is necessary -->        <uptodate property="webdoclet.uptodate">            <srcfiles dir="src/web" includes="**/*.java"/>            <srcfiles dir="${build.dir}/web/gen" includes="**/*.java"/>            <mapper type="glob" from="*.java" to="${build.dir}/web/classes/*.class"/>        </uptodate>        <condition property="webdoclet.unnecessary">            <and>                <equals arg1="${webdoclet.uptodate}" arg2="true"/>                <available file="${build.dir}/webapp/WEB-INF/${webapp.name}.tld"/>            </and>        </condition>    </target>    <!-- List of variables in .properties files that will be replaced at         build time -->    <filterset id="variables.to.replace">        <filter token="APPNAME" value="${webapp.name}"/>        <filter token="ENCRYPT-ALGORITHM" value="${encrypt.algorithm}"/>        <filter token="ERROR-MAILTO" value="${error.mailTo}"/>        <filter token="ERROR-MAILFROM" value="${mail.default.from}"/>        <filter token="ERROR-MAILHOST" value="${mail.host}"/>        <filter token="ERROR-SERVER" value="${error.server}"/>        <filter token="SECURE-LOGIN" value="${secure.login}"/>        <filter token="HIBERNATE-DIALECT" value="${hibernate.dialect}"/>    </filterset>    <!-- List of variables to replace when configuring Tomcat -->    <filterset id="db.variables">        <filter token="DB-DRIVERNAME" value="${database.driver_class}"/>        <filter token="DB-URL" value="${database.url}"/>        <filter token="DB-DIALECT" value="${hibernate.dialect}"/>        <filter token="DB-NAME" value="${database.name}"/>        <filter token="DB-USERNAME" value="${database.username}"/>        <filter token="DB-PASSWORD" value="${database.password}"/>    </filterset>        <filterset id="tomcat.variables">        <filter token="DOC-BASE" value="${web.dir}"/>        <filter token="URI-PATH" value="${dev.uri.path}"/>    </filterset>    <!-- Copy any resource or configuration files -->    <target name="copy-resources" depends="prepare"        description="Copy .properties and .xml files from source directory">        <copy todir="${build.dir}/resources" includeEmptyDirs="no">            <fileset dir="${metadata.dir}/resources">                <exclude name="ApplicationResources_zh*.properties"/>                <exclude name="exceptionResources_zh*.properties"/>                <include name="*.properties"/>                <include name="*.xml"/>                <include name="*.vm"/>            </fileset>            <filterset refid="variables.to.replace"/>            <filterset refid="db.variables"/>        </copy>        <native2ascii src="${metadata.dir}/resources" dest="${build.dir}/resources"             includes="ApplicationResources_zh*.properties,exceptionResources_zh*.properties" encoding="UTF-8"/>    </target>    <!-- =================================================================== -->    <!-- The "copy-web-files" target copies the static web resources portion -->    <!-- of your web application source into the build target area           -->    <!-- =================================================================== -->    <target name="copy-web-files" depends="prepare" description="Copy static files">        <echo message="Copying static files"/>        <!-- Remove the copy block below if you're not displaying version/copyright in the footer -->        <tstamp>            <format property="build.timestamp" pattern="EEEE MMM dd, yyyy 'at' hh:mm a zz"/>        </tstamp>        <copy todir="${build.dir}/webapp/WEB-INF">            <fileset dir="${struts.dir}" includes="*.xml"/>            <fileset dir="${metadata.dir}/spring" includes="**/*.xml"/>            <filterset refid="db.variables"/>        </copy>    </target>        <!-- =================================================================== -->    <!-- The "stage-web" is used to gather all static web recourses in the   -->    <!-- build directory.                                                    -->    <!-- =================================================================== -->    <target name="stage-web" depends="copy-resources,copy-web-files"        description="Calls other targets to gather static resources"/>        <!-- =================================================================== -->    <!-- The "hibernatedoclet" target generates Hibernate mapping files      -->    <!-- based on XDoclet marked-up Plain Old Java Object (POJO)             -->    <!-- =================================================================== -->    <target name="hibernatedoclet" depends="prepare" unless="hibernatedoclet.unnecessary"        description="Generate Hibernate mapping files">        <taskdef name="hibernatedoclet"            classname="xdoclet.modules.hibernate.HibernateDocletTask"            classpathref="xdoclet.classpath"/>                <!-- generate hibernate files -->        <hibernatedoclet destdir="${build.dir}/dao/gen" mergedir="metadata/dao"            excludedtags="@version,@author" addedtags="@xdoclet-generated at ${TODAY}"            force="${xdoclet.force}">            <fileset dir="src/dao"/>            <hibernate validatexml="true" version="3.0"/>        </hibernatedoclet>    </target>        <target name="compile-dao" depends="hibernatedoclet" description="Compile dao module">        <compile module="dao"/>    </target>    <target name="package-dao" depends="prepare,compile-dao" description="Package DAO JAR">        <!-- Copy XML files from source -->        <copy todir="${build.dir}/dao/gen">            <fileset dir="src/dao" includes="**/*.xml"/>            <filterset refid="variables.to.replace"/>        </copy>        <!-- Copy Spring configuration files -->        <jar destfile="${dist.dir}/${webapp.name}-dao.jar">            <manifest>                <attribute name="Class-Path" value="${webapp.name}-dao.jar"/>            </manifest>            <fileset dir="${build.dir}/dao/classes"/>            <fileset dir="${build.dir}/dao/gen" includes="**/*.xml"/>        </jar>    </target>      <!-- Service -->    <target name="compile-service" depends="package-dao" description="Compile service module">        <compile module="service"/>    </target>    <target name="package-service" depends="compile-service">        <jar destfile="${dist.dir}/${webapp.name}-service.jar">            <manifest>                <attribute name="Class-Path"                    value="${webapp.name}-dao.jar ${webapp.name}-service.jar"/>            </manifest>            <fileset dir="${build.dir}/service/classes"/>            <fileset dir="src/service" includes="**/*.xml"/>        </jar>    </target>    <target name="package-webservice">        <ant antfile="build_axis2.xml"/>    </target>
  相关解决方案