0

Trying to make my program send emails to myself, using java, and I am being very unsuccessful. I keep getting an error related to the class

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataHandler at Running.main(Running.java:22).

Caused by: java.lang.ClassNotFoundException: javax.activation.DataHandler

The error I am getting is on this line of code:

Message msg = new MimeMessage(session);

Lion Man
  • 1
  • 1
  • 3

1 Answers1

1

See this line: java.lang.ClassNotFoundException: javax.activation.DataHandler. It means that the DataHandler class could not be found anywhere and hence exception was raised. Upon a quick search, I found that the missing class belongs to JAF (activation.jar).

Basics: Where are files searched during compilation?

  1. Source directories specified by you during java compilation. Usually this is done through any build configuration file like pom.xml for Maven or build.gradle for Gradle.

  2. Dependencies are usually defined and stored in classpath. The class path is a sequence of directories (or zip files) where javac compiler searches for classes not defined in any of the source files.

Unblock by add missing jars to classpath, follow this for eclipse:

  1. Add javax.activation jar to your classpath and check whether this resolves your issue.

  2. Since you are trying to send emails via SMTP, you may want to add JavaMail (mail.jar) to your classpath instead and the other activation.jar would be added automatically because of transitive dependency.

vishwarajanand
  • 1,021
  • 13
  • 23
  • What do you mean by add `javax.activation`? How do I add it? Sorry.. I'm new to this stuff, and very confused. – Lion Man Dec 12 '17 at 12:59
  • Same error getting in Ant project, Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataHandler IDE: Netbeans – makt May 04 '23 at 06:33