0

I am having problem generating the war file correctly with ANT's build.xml for Struts2.

My problem was for the struts.xml, I can't seem to be able to put it to the right place even though I tried to use the tag.

What is the correct way of putting it into the war file? Here is my code (removed the tag as it wasn't working):

<?xml version="1.0" encoding="UTF-8"?>
<project name="Struts2Proj" default="war">

<property name= "build.dir" value="build"/>
<property name= "src.dir" value="src"/>
<property name= "lib.home" value="WebContent/WEB-INF/lib"/>

<target name="clean" description="Clean output directories">
    <delete>
        <fileset dir="classes">
            <include name="**/*.class"/>
        </fileset>
    </delete>
</target>

<target name="build" description="Compile source tree java files">
    <mkdir dir="${build.dir}"/>
    <javac src ="${src.dir}" destdir="${build.dir}" >
       <classpath>
           <path>
                <fileset dir="${lib.home}" />                  
          </path>
        </classpath>

    </javac>
</target>

<target name="war">
    <war destfile="Struts2Project.war" webxml="WebContent/WEB-INF/web.xml">
        <fileset dir="WebContent">
             <include name="**/*.*"/>
        </fileset>
        <lib dir="${lib.home}" /> 
        <classes dir="build/classes"/>

    </war>
</target>

</project>
4

1 回答 1

2

问题似乎出在您的build目标上。您没有将配置文件(如struts.xml)复制到构建路径。请参阅此 ANT 教程:http ://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html#config-files 。

例子:

<target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
    <copy todir="${classes.dir}">
        <fileset dir="${src.dir}" excludes="**/*.java"/>
    </copy>
</target>
于 2012-12-01T09:11:25.040 回答