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

发布于 2024-12-02 07:47:43 字数 4194 浏览 1 评论 0原文

我在这个问题上花了很多时间,我需要 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>

I've been much time on this issue, I need to have javax.servlet.Servlet(also, javax.persistence) available. I downloaded it and put it in all the places I believe make sense(C:\Program Files\Java\jdk1.6.0_20\lib ... C:\Sun\SDK\lib [the Glassfish directory] ). I keep getting errors with this issue. Any clues or tips are appreciated.

Here's the error I get when I run "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

Here is part of 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>

And this is what I believe are the relevant parts of 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜爱纠缠 2024-12-09 07:47:43

我认为这是xml的相关部分

我假设您下载了 servlet-xx.jar 或类似的文件,以及另一个用于持久性类的文件。这些应该位于 ant 构建脚本中的类路径引用的 lib 目录中。然后需要将它们添加到上面的 ant 构建脚本行中。即,将“lib/servlet-xx.jar, lib/persistence.jar”添加到该行的末尾,以获取包含=“...”值。

将下载的 jar 的实际名称替换为我上面使用的名称。

I think this is the relevant part of the xml

I assume you downloaded a servlet-xx.jar or similar and another for the persistence classes. These should go in the lib directory referenced by your classpath in the ant build script. And they then need to be added to the ant build script line above. i.e. add "lib/servlet-xx.jar, lib/persistence.jar" to the end of that line for the includes="... value.

Subsitute the actual names of your downloaded jars for the ones I've used above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文