我在哪里可以找到编译servlet所需的javax.servlet类?

时间:2011-09-01 07:42:15

标签: java ant javac

我在这个问题上花了很多时间,我需要有javax.servlet.Servlet(也就是javax.persistence)。我下载了它并把它放在我认为有意义的所有地方(C:\ Program Files \ Java \ jdk1.6.0_20 \ lib ... C:\ Sun \ SDK \ lib [Glassfish目录])。我一直在弄错这个问题。任何线索或提示都表示赞赏。

这是我运行“ant”时遇到的错误:

    [javac]     public void service(HttpServletRequest request, HttpServletRespo
nse response) throws ServletException, IOException;
    [javac]                         ^
    [javac] C:\petstore~svn\trunk\ws\apps\petstore\src\java\com\sun\javaee\bluep
rints\petstore\controller\ControllerAction.java:16: cannot find symbol
    [javac] symbol  : class HttpServletResponse
    [javac] location: interface com.sun.javaee.blueprints.petstore.controller.Co
ntrollerAction
    [javac]     public void service(HttpServletRequest request, HttpServletRespo
nse response) throws ServletException, IOException;
    [javac]                                                     ^
    [javac] C:\petstore~svn\trunk\ws\apps\petstore\src\java\com\sun\javaee\bluep
rints\petstore\controller\ControllerAction.java:16: cannot find symbol
    [javac] symbol  : class ServletException
    [javac] location: interface com.sun.javaee.blueprints.petstore.controller.Co
ntrollerAction
    [javac]     public void service(HttpServletRequest request, HttpServletRespo
nse response) throws ServletException, IOException;
    [javac]
                     ^
    [javac] C:\petstore~svn\trunk\ws\apps\petstore\src\java\com\sun\javaee\bluep
rints\petstore\controller\ControllerServlet.java:16: package javax.servlet does
not exist
    [javac] import javax.servlet.ServletConfig;
    [javac]                     ^
    [javac] 100 errors

BUILD FAILED
C:\petstore~svn\trunk\ws\bp-project\command-line-ant-tasks.xml:80: Compile faile
d; see the compiler error output for details.

Total time: 2 seconds

以下是command-line-ant-tasks.xml的一部分:

<dirname property="antfile.dir" file="${ant.file}"/>
<path id="classpath">
    <fileset dir="${javaee.home}" includes="lib/javaee.jar, lib/appserv-rt.jar, lib/appserv-ws.jar"/>
    <pathelement location="${build.classes.dir}"/>
    <pathelement path="${javac.classpath}"/>
    <pathelement path="${extra.classpath}"/>
    <path refid="javaee.classpath" />
</path>

<!-- the includeantruntime was added 8/31 -cp="C:\servlet"  -->
<target name="bpp-actual-compilation" if="has-java-sources">
    <echo>Compiling ${module.name}</echo>
    <mkdir dir="${build.classes.dir}"/>
    <javac srcdir="${src.dir}"
        source="${default.javac.source}"
        target="${default.javac.target}"
        excludes="${javac.excludes}"
        debug="${javac.debug}"

        debuglevel="${javac.debuglevel}"
        destdir="${build.classes.dir}"
        includeantruntime="false"
        includes="**">
        <classpath refid="classpath"/>
    </javac>
</target>

这就是我认为build.xml的相关部分:

<target name="insert-proxy-settings">
    <copy todir="${build.web.dir}/WEB-INF/" file="web/WEB-INF/web.xml"/>
    <concat destfile="${build.dir}/proxy.properties">proxy.host=${proxy.host}
        proxy.port=${proxy.port}
        <filterchain>
            <expandproperties/>
        </filterchain>
    </concat>
    <!-- Replace value of the proxy settings in web.xml for Google maps -->
    <replace file="${build.web.dir}/WEB-INF/web.xml" propertyFile="${build.dir}/proxy.properties">          
        <replacefilter token="@@proxy.host@@" property="proxy.host"/>
        <replacefilter token="@@proxy.port@@" property="proxy.port"/>
    </replace>        
</target>

<target name="unzipIndexes">
    <unzip src="lib/petstoreIndexes.zip" dest="${javaee.domaindir}/lib/petstore" overwrite="true"/>
</target>

<target name="setup" depends="init, create-bp-ui-5-jar">
    <mkdir dir="${javaee.domaindir}/lib/petstore/images"/>
    <ant dir="." antfile="setup/setup.xml" target="setup" inheritAll="false" inheritRefs="false"/>
    <antcall target="unzipIndexes"/>
</target>

1 个答案:

答案 0 :(得分:1)

我认为这是xml的相关部分

我假设您为持久性类下载了servlet-xx.jar或类似内容。这些应该放在ant构建脚本中类路径引用的lib目录中。然后需要将它们添加到上面的ant构建脚本行中。即将“lib / servlet-xx.jar,lib / persistence.jar”添加到该行的末尾,用于includes =“... value。

为我上面使用过的罐子的实际名称添加。