Jude
Jude

Reputation: 428

About Java EE classpath

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.

Upvotes: 0

Views: 1507

Answers (2)

Brent Worden
Brent Worden

Reputation: 10984

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.

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 359856

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.

Upvotes: 1

Related Questions