开发者

Where do I find the javax.servlet classes needed to compile my servlet?

开发者 https://www.devze.com 2023-04-01 00:22 出处:网络
I\'ve been much time on this issue, I need to havejavax.servlet.Servlet(also, javax.persistence) available. I downloaded it and put it in all the places I believe make sense(C:\\Program Files\\Java\\j

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, HttpSe开发者_如何学PythonrvletRespo
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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号