在哪里可以找到编译 servlet 所需的 javax.servlet 类?
我在这个问题上花了很多时间,我需要 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是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.