Ant构建期间的部署错误

时间:2012-07-26 07:11:33

标签: java web-services spring ant

我正在使用spring和webservice。所以我将web.xml定义为

<?xml version="1.0" encoding="UTF-8"?>
<project name="service" default="deploy">
    <property name="builddir" value="build" />
    <property name="srcdir" value="../src" />
    <property name="deploydir" value="deploy" />
    <property name="wardir" value="../WebContent"/>
    <property name="libdir" value="${wardir}/WEB-INF/lib/" />


    <target name="cleanstart">
        <delete dir="${builddir}" failonerror="true" />
        <echo message="Creating build directories" />
        <mkdir dir="${builddir}" />
        <mkdir dir="${builddir}/service/WEB-INF/classes" />
        <mkdir dir="${deploydir}" />
    </target>

    <target name="service.war">

        <path id="basepath">
            <!--<fileset dir="${libdir}">
                <include name="**/*.jar" />
            </fileset>
            -->
            <fileset dir="${wardir}/WEB-INF/lib">
                <include name="**/*.jar" />
            </fileset>

        </path>
        <javac srcdir="${srcdir}/" destdir="${builddir}/service/WEB-INF/classes">
            <classpath refid="basepath" />
        </javac>

        <war warfile="${builddir}/service.war" webxml="${wardir}/WEB-INF/web.xml" update="update">
            <classes dir="${builddir}/service/WEB-INF/classes" />
            <fileset dir="${wardir}">
                <exclude name="**/*web.xml" />
            </fileset>

        </war>
    </target>


    <target name="deploy" depends="cleanstart, service.war">
        <copy file="${builddir}/service.war" todir="${deploydir}">
        </copy>
    </target>

</project>

为spring定义了beans.xml,并使用以下代码加载了spring:

ServletConfig servletConfig ;
ServletContext servletContext = servletConfig.getServletContext();
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);

在ant build期间,我得到例外情况如下:

   service.war:
            [javac] /home/vshankar/service_spring/buildTools/build.xml:36: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
            [javac] Compiling 20 source files to /home/vshankar/service_spring/buildTools/build/service/WEB-INF/classes
            [javac] /home/vshankar/service_spring/src/com/f/a/services/servicename/Service.java:6: package javax.servlet does not exist
            [javac] import javax.servlet.ServletConfig;
            [javac]                     ^
            [javac] /home/vshankar/service_spring/src/com/f/a/services/servicename/Service.java:7: package javax.servlet does not exist
            [javac] import javax.servlet.ServletContext;
            [javac]                     ^
            [javac] /home/vshankar/service_spring/src/com/f/a/services/servicename/Service.java:49: cannot find symbol
            [javac] symbol  : class ServletConfig
            [javac] location: class com.f.a.services.servicename.Service
            [javac]     ServletConfig servletConfig ;
            [javac]     ^
            [javac] /home/vshankar/service_spring/src/com/f/a/services/servicename/Service.java:50: cannot find symbol
            [javac] symbol  : class ServletContext
            [javac] location: class 
com.f.a.services.servicename.Service
            [javac]     ServletContext servletContext = servletConfig.getServletContext();
            [javac]     ^
            [javac] 4 errors

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

在构建项目时,需要将servlet jar文件放到类路径中。 (请注意,不建议将此文件打包到您的耳朵/ war文件中)