jar -cvf my.war *.*ant创建一个target,
 <target name="war" depends="compile">      <war warfile="${build}/my.war" webxml="${build}/WEB-INF/web.xml">
 <lib dir="${build}/WEB-INF/lib"/>
 <classes dir="${build}/WEB-INF/classes/"/>
 <fileset dir="${build}"/>    </war> 
    
 </target>把build.xml拷贝到你的WEB根目录下,在改目录下执行ant -buildfile build.xml war

解决方案 »

  1.   

    <project name="geezer_project" default="dist" basedir=".">
     <property environment="myenv" />
            <property name="servletpath"  value="${myenv.TOMCAT_HOME}/common/lib/servlet-api.jar" />
            <property name="mysqlpath" value="c:/resin/doc/15com/WEB-INF/lib/mm.mysql-2.0.4-bin.jar" />
      <property name="src" location="src"/>
      <property name="build" location="build"/>
      <target name="init">
        <mkdir dir="${build}"/>
         <mkdir dir="${build}\WEB-INF" />
         <mkdir dir="${build}\WEB-INF\lib" />
     <mkdir dir="${build}\WEB-INF\classes" />
      </target>
      <target name="compile" depends="init"
            description="compile the source " >   
          <javac srcdir="${src}"
                 destdir="${build}/WEB-INF/classes"
                 classpath="${servletpath}:${mysqlpath}">
         </javac>
      </target>
     <target name="war" depends="compile">  
        <war warfile="${build}/bookstore.war" webxml="${build}/WEB-INF/web.xml">
     <lib dir="${build}/WEB-INF/lib"/>
     <classes dir="${build}/WEB-INF/classes/"/>
     <fileset dir="${build}"/>
        </war> 
     </target>
      <target name="dist" depends="compile"
            description="generate the distribution" >
        <jar jarfile="MyProject.jar" basedir="${build}"/>
      </target>
      <target name="clean"
            description="clean up" >
        <delete dir="${build}"/>
        <delete dir="${dist}"/>
      </target>
    </project>上面是完整的,你搜索ANT文章,很多的。
      

  2.   

    http://ant.apache.org/manual/CoreTasks/war.html作这种东西简单,好好看看Ant得Manual!你说你会用Ant编译程序,看看这个网页就什么都会了War
    Description
    An extension of the Jar task with special treatment for files that should end up in the WEB-INF/lib, WEB-INF/classes or WEB-INF directories of the Web Application Archive.(The War task is a shortcut for specifying the particular layout of a WAR file. The same thing can be accomplished by using the prefix and fullpath attributes of zipfilesets in a Zip or Jar task.)The extended zipfileset element from the zip task (with attributes prefix, fullpath, and src) is available in the War task.
      

  3.   

    我已经制作了war包,但是还有几个问题:我的target如下:
    <target name="war" depends="compile">  
      <war warfile="${warDir}\mlmproject.war" webxml="${webDir}\WEB-INF\web.xml">
        <lib dir="${webDir}\WEB-INF\lib"/>
        <classes dir="${buildDir}"/>
        <fileset dir="${webDir}"/>
      </war> 
    </target>
    我确认路径都对1.制作war包时,提示如下错误:
          [war] Warning: selected war files include a WEB-INF/web.xml which will be ignored (please use webxml attribute to war task)
      这个错误是什么意思?
    2.在我的web-inf\classes里面有个ChangeReqEncoding.class类,使解决中文问题的filter,这个类在war包中除下了两次,同时在web-inf\lib目录下,class12.jar,smartupload.jar也都是双份
    3.我的项目下有个upload目录,里面是中文的文件夹,做成war后看到的是中文乱码,在我的build.xml文件中第一行已经是:<?xml version="1.0" encoding="gb2312"?>请问如上是什么问题?谢谢
      

  4.   

    谢谢二位,中文问题也搞定了,<target name="war" depends="compile" encoding="gb2312">但是现在前两个问题不知道是怎么回事
      

  5.   

    接贴,现在就是jar是双份的,真郁闷,谢谢两位