关于 Java EE 类路径
我正在为我的学校使用 NetBeans 开发基于 Java EE 框架的在线会议系统。我的项目包含 Java EE 库,其中包含 javax.mail
包。
我在代码中使用 javax.mail.authenticator 类,一切似乎都正常。但是,当我运行该项目并尝试使用该系统发送电子邮件时,出现问题,说找不到类javax.mail.authenticator
。
然后我将文件mail.jar和authenticator.jar放在文件夹WEB-INF/lib中,之后就可以正确发送电子邮件了。我不知道为什么它找不到类验证器以及为什么这两个 jar 文件应该放在那里?
PS:我使用 Tomcat 6 作为我的 Web 服务器。
I am developing an online conference system based on Java EE framework using NetBeans for my school. My project contains the Java EE library which has javax.mail
package.
I use the javax.mail.authenticator
class in my code and everything seems to be OK. However, when I run the project and try to send email with this system, problem occurs, saying it can not find class javax.mail.authenticator
.
Then I put the files mail.jar and authenticator.jar in folder WEB-INF/lib, after that it can send email correctly. I don't know why it can not find the class authenticator and why this two jar files should be put there?
PS: I use Tomcat 6 as my web server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 构建路径上的类和类路径上的类是有区别的。通过将
mail.jar
和authenticator.jar
放入WEB-INF/lib
中,您已将它们放入 Tomcat 的类路径中,以便 Tomcat 可以“看到“运行时的那些类。推荐阅读:类路径和构建之间有什么区别路径
PS我认为你的意思是Java EE。它已经大约 5 年没有被称为 J2EE 了。
There is a difference between having a class on the Java build path, and on the classpath. By putting
mail.jar
andauthenticator.jar
intoWEB-INF/lib
, you have put them into Tomcat's classpath so that Tomcat can "see" those classes at runtime.Recommended reading: What is the difference between Class Path and Build Path
P.S. I think you mean Java EE. It hasn't been called J2EE for ~5 years now.
当您将应用程序部署到 Java EE 容器(例如 Tomcat)时,会在某些位置加载类和 jar 以形成应用程序的类路径。对于 Web 应用程序(战争),类从 WEB-INF/classes 和 WEB-INF/lib 中的 jar 加载。
When you deploy an application to a Java EE container, like Tomcat, there are certain places classes and jars are loaded to form an application's classpath. For web applications (a war), classes are loaded from WEB-INF/classes and from jars in the WEB-INF/lib.