为了账号安全,请及时绑定邮箱和手机立即绑定

错误:即使添加了 CLASSPATH 变量,包 javax.servlet.http 也不存在

错误:即使添加了 CLASSPATH 变量,包 javax.servlet.http 也不存在

繁星coding 2021-10-27 17:05:35
我正在尝试实现基本的 HelloServlet.java 程序。但它似乎产生了这些错误HelloServlet.java:7: error: cannot find symbolpublic class HelloServlet extends HttpServlet {                                  ^  symbol: class HttpServletHelloServlet.java:11: error: cannot find symbol   public void init() throws ServletException {                             ^  symbol:   class ServletException  location: class HelloServletHelloServlet.java:16: error: cannot find symbol   public void doGet(HttpServletRequest request, HttpServletResponse response)                     ^  symbol:   class HttpServletRequest  location: class HelloServletHelloServlet.java:16: error: cannot find symbol   public void doGet(HttpServletRequest request, HttpServletResponse response)                                                 ^  symbol:   class HttpServletResponse  location: class HelloServletHelloServlet.java:17: error: cannot find symbol      throws ServletException, IOException {             ^  symbol:   class ServletException  location: class HelloServletHelloServlet.java:3: error: package javax.servlet does not existimport javax.servlet.*;^HelloServlet.java:4: error: package javax.servlet.http does not existimport javax.servlet.http.*;^7 errors我已经为 jar 文件添加了 CLASSPATHnithinchandranp@b-40:~$ echo ${CLASSPATH}/home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/*nithinchandranp@b-40:~$ 现在我做错了什么?请帮忙..
查看完整描述

3 回答

?
慕容森

TA贡献1853条经验 获得超18个赞

末尾带有 * 的类路径不适用于 jar 数据集。您必须将每个 jar 放在类路径中。


查看完整回答
反对 回复 2021-10-27
?
小唯快跑啊

TA贡献1863条经验 获得超2个赞

这是我的错误。


这就是我通过命令行创建 CLASSPATH 的方式


 export CLASSPATH=/home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/*

我创建的目录不是ApacheTomcat,而是Apache Tomcat(中间有一个空格)。


也许这就是 CLASSPATH 变量无法识别正确位置的原因。


我将目录名称更改为 ApacheTomcat(删除了空格)。


现在我在 .bashrc 文件中定义了 CLASSPATH 变量,如下所示:


#classpath

export CLASSPATH=/home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/*

现在,当我执行 echo${CLASSPATH} 时,我得到了我提到的所有 jar 文件。


nithinchandranp@b-40:~$ echo ${CLASSPATH}

/home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/annotations-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina-ant.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina-ha.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina-storeconfig.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/catalina-tribes.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/ecj-4.6.3.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/el-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/jasper-el.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/jasper.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/jaspic-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/jsp-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/servlet-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-api.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-coyote.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-dbcp.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-i18n-es.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-i18n-fr.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-i18n-ja.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-i18n-ru.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-jdbc.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-jni.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-util.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-util-scan.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/tomcat-websocket.jar /home/nithinchandranp/ApacheTomcat/apache-tomcat-8.5.34/lib/websocket-api.jar



查看完整回答
反对 回复 2021-10-27
  • 3 回答
  • 0 关注
  • 278 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信