2009-04-17 10 views
1

Ich möchte eine WAR-Datei für das Projekt erstellen. Der Code funktioniert gut zum Erstellen einer JAR-Datei. Wenn ich die folgende ant build.xml ausführen, gibt es immer noch die Nachricht JAR-Datei BUILD SUCCESSFULL.Erstellen Sie eine WAR-Datei

<project name="struts-spring" basedir="../" default="all"> 
    <!-- Project settings --> 
    <property name="project.title" value="Sufalam Struts 2 Tutorials"/> 
    <property name="project.jar.file" value="struts-spring.jar"/> 

     <path id="class.path"> 

     <fileset dir="lib"> 

      <include name="**/*.jar"/> 

     </fileset> 

     <fileset dir="libext"> 

      <include name="**/*.jar"/> 

     </fileset> 

     </path> 

     <!-- Classpath for Project --> 

     <path id="compile.classpath"> 

      <pathelement path ="lib/commons-beanutils.jar"/> 

      <pathelement path ="lib/commons-digester.jar"/> 

      <pathelement path ="lib/struts.jar"/> 

      <pathelement path ="libext/servlet-api.jar"/> 

      <pathelement path ="libext/catalina-ant.jar"/> 

      <pathelement path ="classes"/> 

      <pathelement path ="${classpath}"/> 

     </path> 

     <!-- Check timestamp on files --> 

     <target name="prepare"> 

      <tstamp/> 
      <copy 
       file="src/struts.xml" 
       todir="src/classes"/> 


     </target> 
     <!-- Copy any resource or configuration files --> 

     <target name="resources"> 

      <copy todir="classes" includeEmptyDirs="no"> 

       <fileset dir="src/java"> 

       <patternset> 

        <include name="**/*.conf"/> 

        <include name="**/*.properties"/> 

        <include name="**/*.xml"/> 

       </patternset> 

       </fileset> 

      </copy> 

     </target> 

     <!-- Normal build of application --> 

     <target name="compile" depends="prepare,resources"> 

      <javac srcdir="src" destdir="classes" 
         debug="true" debuglevel="lines,vars,source"> 

       <classpath refid="class.path"/> 

      </javac> 

      <jar 

      jarfile="lib/${project.jar.file}" 

      basedir="classes"/> 

     </target> 
     <!-- Remove classes directory for clean build --> 

     <target name="clean" 

      description="Prepare for clean build"> 

      <delete dir="classes"/> 

      <mkdir dir="classes"/> 

     </target> 

     <!-- Build Javadoc documentation --> 

     <target name="javadoc" 

     description="Generate JavaDoc API docs"> 

      <delete dir="./doc/api"/> 

      <mkdir dir="./doc/api"/> 

      <javadoc sourcepath="./src/java" 

       destdir="./doc/api" 

       classpath="${servlet.jar}:${jdbc20ext.jar}" 

       packagenames="*" 

       author="true" 

       private="true" 

       version="true" 

       windowtitle="${project.title} API Documentation" 

       doctitle="&lt;h1&gt;${project.title} 
          Documentation (Version ${project.version})&lt;/h1&gt;" 

       bottom="Copyright &#169; 2002"> 

       <classpath refid="compile.classpath"/> 

      </javadoc> 

     </target> 

     <!-- Build entire project --> 

     <target name="project" depends="clean,prepare,compile"/> 

     <!-- Create binary distribution --> 

     <target name="dist" 

      description="Create binary distribution"> 

      <mkdir 

      dir="${distpath.project}"/> 

<!--   <jar 

      jarfile="${distpath.project}/${project.distname}.jar" 

      basedir="./classes"/> 

      <copy 

      file="${distpath.project}/${project.distname}.jar" 

      todir="${distpath.project}"/>--> 



      <war 

      basedir="../" 

      warfile="${distpath.project}/${project.distname}.war" 

      webxml="web.xml"> </war> 

      <copy file="${distpath.project}/${project.distname}.war" todir="${distpath.project}"/> 

      <!--<exclude name="${distpath.project}/${project.distname}.war"/>--> 

    </target> 

    <!-- Build project and create distribution--> 
    <target name="all" depends="project"/> 
</project> 

bitte helfen Sie mir eine Kriegsdatei zu erstellen. Vielen Dank im Voraus.

+0

Was ist ein Krieg-Datei? –

Antwort

5

Ich sehe nicht, dass Sie der Kriegsaufgabe sagen, welche Dateien in die Kriegsdatei zu legen sind. Vielleicht möchten Sie sich die Beispiele here ansehen. Ant hat fantastische Dokumentation, denke ich. Hier

ist ein Beispiel für die Verwendung der Krieg Aufgabe aus den obigen Link:

<war destfile="myapp.war" webxml="src/metadata/myapp.xml"> 
    <fileset dir="src/html/myapp"/> 
    <fileset dir="src/jsp/myapp"/> 
    <lib dir="thirdparty/libs"> 
    <exclude name="jdbc1.jar"/> 
    </lib> 
    <classes dir="build/main"/> 
    <zipfileset dir="src/graphics/images/gifs" 
      prefix="images"/> 
</war> 
+1

das Ant-Handbuch ist in der Tat großartige Dokumentation –

+0

Meine ziemlich generische build.xml für Java Webapps ist hier. Es verwendet dynamic manifest.mf, jar compilation, war packaging und folder strcuture ist sehr schlank. http://stackoverflow.com/a/18460429/185565 – Whome