在ANT版本中未生成的类文件

时间:2015-03-17 11:46:49

标签: java class ant jenkins war

我正在使用一个正确的build.xml来生成一个war文件。成功创建一个WAR文件,但是没有类文件!!。我在eclipse或cmd提示符下尝试了相同的但是最终的war文件不包含类文件只包含库等。 这是我的build.xml:

<?xml version="1.0" ?> 
<project name="Westpac" default="war" basedir="C:\\Users\\M1019779\\.jenkins\\workspace\\Test GIT">
    <property name="configuration" value="stage"/>
    <target name="init" depends="clean">
        <mkdir dir="build/classes"/>
        <mkdir dir="build/lib"/>
        <copy todir="build/lib">
            <fileset dir="C:\\java\\wp_lib">
                <include name="*.jar"/>
            </fileset>
        </copy>
    </target>
    <path id="build.classpath">
        <fileset dir="build/lib">
        </fileset>
    </path>

    <target name="compile" depends="init" description="Compiles the java source">
        <echo message="Building for ${configuration}" />
        <javac destdir="build/classes" debug="true" srcdir="src">
            <classpath refid="build.classpath" />
            <!-- <classpath> -->
                <!-- <fileset dir="build/compile"> -->
                    <!-- <include name="**/*.jar" /> -->
                    <!-- <include name="*.jar" /> -->
                    <!-- </fileset></classpath>-->
        </javac>
        <!--must copy non java resources manually-->
        <copy todir="build/classes/">
            <fileset file="src/*.properties" />
        </copy>
        <copy todir="build/classes/conf">
            <fileset dir="src/conf" />
        </copy>
        <copy todir="build/classes/com/bcsg/saas/db">
            <fileset dir="src/com/bcsg/saas/db" />
        </copy>
        <copy todir="build/classes/pdf">
            <fileset dir="src/pdf" />
        </copy>

        <copy todir="build/classes/vmTemplate">
            <fileset dir="src/vmTemplate" />
        </copy>     
    </target>

    <target name="clean">
        <delete dir="dist" />
        <delete dir="build" />
    </target>

    <target name="war" depends="compile" description="Packages up the java classes, along with all static assets and the libraries required for runtime into a war file">       
        <war destfile="dist/westpac-${configuration}.war" webxml="WebContent/WEB-INF/web.xml">
            <classes dir="build/classes"/>
            <fileset dir="WebContent"/>
            <fileset file="build/build.properties" />
            <lib dir="build/lib" />
        </war>
    </target>       
</project>

1 个答案:

答案 0 :(得分:0)

您的war任务有一个嵌套的<classes>元素,is a FileSet, per the Ant documentation。这意味着您可以明确<include>的内容,并识别.class文件。

尝试更改战争任务以包含此内容:

<classes dir="build/classes">
    <include name="**/*.class"/>
</classes>