0

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.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Jude
  • 428
  • 4
  • 8

2 Answers2

1

There is a difference between having a class on the Java build path, and on the classpath. By putting mail.jar and authenticator.jar into WEB-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.

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
0

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.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Brent Worden
  • 10,624
  • 7
  • 52
  • 57