处理 Java servlet“javax.servlet”找不到包
这不是一个非常常见的实现,但使用Processing作为Java Servlet之前已经在之前的帖子中讨论过(1,2)。我一直在Processing 中开发一个程序来用作Java servlet。但是,当我在处理草图中有代码(例如第一个链接的示例)时,我收到错误消息
The package 'javax.servlet' does not exist. You might be missing a library.
我在 XP 上运行 Tomcat 5.5 服务,并且我的环境变量如下
CLASSPATH = C:\tomcat\common\lib\servlet-api.jar
CATALINA_HOME = C:\tomcat
JAVA_HOME = C:\Program Files\Java\jdk1.6.0_21
JRE_HOME = C:\Program Files\Java\jre6
我一直在尝试诊断为什么 javax .servlet 包在很长时间内都无法被 Processing 识别,除了修复环境变量以识别 tomcat 库之外,网上似乎没有任何解释可以提供。我还尝试将 servlet-api.jar 和 jsp-api.jar 文件作为一种自定义处理库放入处理中,但它们在那里也无法识别,当我尝试在 tomcat/webapps 文件夹中运行程序时也无法识别它们。
我也尝试
javap -classpath my;class;path javax.servlet.Servlet
过cmd,它给了我同样的错误。
我对 Tomcat 还不太熟悉,所以如果这是我不熟悉的结果,请原谅我。如果任何比我更有知识的人都可以解释为什么处理无法识别这个包,那就太棒了。非常感谢~
Not a very common implementation, but using Processing as a Java Servlet has been discussed in previous posts before (1, 2). I have been developing a program in Processing to use as a Java servlet. However, when I have code (such as like the first linked example) in a Processing sketch, I get the error message
The package 'javax.servlet' does not exist. You might be missing a library.
I have Tomcat 5.5 service running on XP, and my environment variables are as follows
CLASSPATH = C:\tomcat\common\lib\servlet-api.jar
CATALINA_HOME = C:\tomcat
JAVA_HOME = C:\Program Files\Java\jdk1.6.0_21
JRE_HOME = C:\Program Files\Java\jre6
I have been trying to diagnose why the javax.servlet packages are not recognized by Processing for many hours and there is nothing online that seems to yield an explanation other than fixing the environment variables to recognize the tomcat libraries. I have also tried to put the servlet-api.jar and jsp-api.jar files in Processing as a kind of custom Processing library but they are not recognized there either, nor when I try to run the program within the tomcat/webapps folder.
I also have tried
javap -classpath my;class;path javax.servlet.Servlet
on the cmd and it gave me the same error.
I'm not that good with Tomcat yet so please forgive me if this is a result of my unfamiliarity. If anyone more knowledgeable than I can shed some light as to why Processing cannot recognize this package would be tremendous. Thanks so much~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这就是问题所在。你的类路径应该是上一级,即
CLASSPATH = C:\tomcat\common\lib\
这应该可以正常工作。
This is the problem . Your classpath should be one level up i.e
CLASSPATH = C:\tomcat\common\lib\
This should work fine.
右键单击我的电脑->属性->高级->环境变量->环境变量
设置一个新的用户变量名称作为类路径,并给出 servlet-api.jar 文件所在位置的变量值(适用于 tomcat webserver),例如:->
变量名:类路径
变量值:D:\Tomcat\lib\servlet-api.jar
现在您可以运行反汇编程序来找出 servlet 类和接口信息
Right Click on MyComputer->Properties->Advanced->Environment Variables->
Set a new user variable name as classpath and give the variable value where your servlet-api.jar file is located (applicable for tomcat webserver), for example:->
variablename: classpath
variablevalue: D:\Tomcat\lib\servlet-api.jar
Now you can run your disassembler to find out the servlet class and interface information
如果无法加载 servlet 包,请尝试将环境变量 CLASSPATH 设置为 .;C:\tomcat\common\lib\servlet-api.jar。那应该有帮助。
If you are not able to load the servlet package, try setting the environment variable CLASSPATH to .;C:\tomcat\common\lib\servlet-api.jar. That should help.
好的!...我买了一台新笔记本电脑,也遇到了同样的问题,我希望这也能解决您的 Windows 10 设备上的问题。
首先要知道该错误只是由于路径或类路径不正确或不完整造成的。安装 Tomcat 和 JDK 后,设置环境变量如下(位置可能会根据您的安装而有所不同):
JAVA_HOME = C:\Program Files (x86)\Java\jdk1.7.0_80
JRE_HOME = C:\Program Files (x86)\Java \jre7
CATALINA_HOME = C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0
路径 = C:\Program Files (x86)\Java\jdk1.7.0_80\bin; C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\bin;
CLASSPATH = C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar; C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar; JAVA_HOME\lib
确保您的类路径指向提到的 jar 文件,因为 javax 包含在其中(尝试使用 winrar 检查内部内容)。
保存设置后,使用 javap javax.servlet.Servlet 进行测试
如果您仍然遇到任何问题,请分享错误消息和屏幕截图。
Ok!.. i bought a new laptop and was faced the same problem, well i hope this would fix the issue on your windows 10 device as well.
First of all know that the error is just due to incorrect or incomplete path or classpath. After Installing Tomcat and JDK set the environment variable as follows(Location may vary as per your installation):
JAVA_HOME = C:\Program Files (x86)\Java\jdk1.7.0_80
JRE_HOME = C:\Program Files (x86)\Java\jre7
CATALINA_HOME = C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0
PATH = C:\Program Files (x86)\Java\jdk1.7.0_80\bin; C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\bin;
CLASSPATH = C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar; C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar; JAVA_HOME\lib
make sure that your classpath directs the mentioned jar files, as javax is included in it(try using winrar for checking the inner contents).
After saving the setting, Test using javap javax.servlet.Servlet
Well if you still face any issue please share the error message and screenshot.
右键单击我的电脑->属性->高级->环境变量->环境变量
设置一个新的用户变量名称作为类路径,并给出 servlet-api.jar 文件所在位置的变量值(适用于 tomcat webserver),例如:->
变量名:“CLASSPATH”
变量值:D:\tomcat\lib\servlet-api.jar;。
然后检查打开命令并键入:-
C:\Users\akash>javap javax.servlet.Servlet
小错误,因为 javax 旧版本
错误:找不到类:javax.servlet.Servlet
然后检查打开命令和类型:-
C:\Users\akash>javap jakarta.servlet.Servlet
这应该可以正常工作。
Right Click on MyComputer->Properties->Advanced->Environment Variables->
Set a new user variable name as classpath and give the variable value where your servlet-api.jar file is located (applicable for tomcat webserver), for example:->
variablename: "CLASSPATH"
variablevalue: D:\tomcat\lib\servlet-api.jar;.
Then Check Open Command and Type :-
C:\Users\akash>javap javax.servlet.Servlet
small error because javax old version
Error: class not found: javax.servlet.Servlet
Then Check Open Command and Type :-
C:\Users\akash>javap jakarta.servlet.Servlet
This should work fine.
可能是因为 Tomcat 不在 Java 构建路径中。尝试将 Tomcat 添加到您的库中
1) 右键单击您的项目文件夹 > 构建路径> 配置构建路径
2) 单击库选项卡 >单击添加库按钮
3) 选择服务器运行时< /strong>>单击下一步按钮
4) 选择您的服务器>单击完成按钮
Probably because Tomcat is not in the Java Build Path. Try add Tomcat to your library
1) Right-click on your project folder > Build Path > Configure Build Path
2) Click on Library tab > click Add Library button
3) Select Server Runtime > click Next button
4) Select your server > click Finish button