java.lang.NoClassDefFoundError: javax/mail/MessagingException

JBoss Issue Tracker | Agustin Treceno | 2 years ago
  1. 0

    I am trying to use the JBoss mail service with the following class: {code:java} import javax.annotation.Resource; import javax.mail.Address; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SendMail2 { @Resource(mappedName = "java:jboss/mail/Default") private static Session mailSession; /** * @param args */ public static void main(String[] args) { try { MimeMessage m = new MimeMessage(mailSession); Address from = new InternetAddress("agustin@abc.co.uk"); Address[] to = new InternetAddress[] { new InternetAddress("agustin@abc.co.uk") }; m.setFrom(from); m.setRecipients(Message.RecipientType.TO, to); m.setSubject("JBoss AS 7 Mail"); m.setSentDate(new java.util.Date()); m.setContent("Mail sent from JBoss AS 7", "text/plain"); Transport.send(m); System.out.println("Mail sent!"); } catch (MessagingException e) { e.printStackTrace(); System.out.println("Error in Sending Mail: " + e); } } } {code} Then compile and execute the class using the jboss module loader: {noformat} $ javac -classpath /opt/jboss-eap-6.2/modules/system/layers/base/javax/mail/api/main/mail-1.4.5-redhat-1.jar ~/SendMail2.java $ /usr/java/jdk1.7.0_51/bin/java -jar jboss-modules.jar -mp modules -cp /home/agustin SendMail2 Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:270) at org.jboss.modules.Module.run(Module.java:282) at org.jboss.modules.Main.main(Main.java:455) Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException from [Module "Classpath:main" from Class path module loader for path '/home/agustin'] at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) ... 4 more {noformat} As you can see the ModuleClassLoader cannot find the class {{javax.mail.MessagingException}} which is in the javax.mail.api module. Now if I specify the JAR of that module in the classpath... it works! {noformat} $ /usr/java/jdk1.7.0_51/bin/java -jar jboss-modules.jar -mp modules -cp /home/agustin:/opt/jboss-eap-6.2/modules/system/layers/base/javax/mail/api/main/mail-1.4.5-redhat-1.jar SendMail2 Mail sent! {noformat} More info about the environment: {noformat} $ uname -a Linux mars 2.6.32-431.11.2.el6.x86_64 #1 SMP Mon Mar 3 13:32:45 EST 2014 x86_64 x86_64 x86_64 GNU/Linux $ cat version.txt JBoss Enterprise Application Platform - Version 6.2.0.GA $ bin/run.sh -V ======================================================================================== To start a JBoss Enterprise Application Platform 6 Standalone Server, a single server instance, use the command: /opt/jboss-eap-6.2/bin/standalone.sh To start a JBoss Enterprise Application Platform 6 Managed Domain, allowing control and management of multiple instances, use the command: /opt/jboss-eap-6.2/bin/domain.sh ======================================================================================== $ /usr/java/jdk1.7.0_51/bin/java -jar jboss-modules.jar -version JBoss Modules version 1.3.0.Final-redhat-2 {noformat}

    JBoss Issue Tracker | 2 years ago | Agustin Treceno
    java.lang.NoClassDefFoundError: javax/mail/MessagingException
  2. 0

    Vraptor 3 - Hibernate 4

    com.br | 1 year ago
    java.lang.NoClassDefFoundError: org/hibernate/criterion/Criterion
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Vraptor 3 - Hibernate 4 - Front-end - GUJ

    com.br | 11 months ago
    java.lang.NoClassDefFoundError: org/hibernate/criterion/Criterion
  5. 0

    Problem deploying JBoss AS 7.1.0 - ClassNotFoundException

    Coderanch | 5 years ago | Rodrigo Sasaki
    javax.resource.ResourceException: Could not create connection

  1. Andreas Häber 9 times, last 2 weeks ago
  2. Reich 8 times, last 2 weeks ago
  3. andyglick 1 times, last 2 months ago
  4. Cafecanudo 3 times, last 2 months ago
  5. pbabcsany 2 times, last 2 months ago
3 more registered users
75 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.ClassNotFoundException

    javax.mail.MessagingException from [Module "Classpath:main" from Class path module loader for path '/home/agustin']

    at org.jboss.modules.ModuleClassLoader.findClass()
  2. JBoss Modules
    ConcurrentClassLoader.loadClass
    1. org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197)
    2. org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443)
    3. org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431)
    4. org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373)
    5. org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118)
    5 frames
  3. Java RT
    Class.forName
    1. java.lang.Class.forName0(Native Method)
    2. java.lang.Class.forName(Class.java:270)
    2 frames
  4. JBoss Modules
    Main.main
    1. org.jboss.modules.Module.run(Module.java:282)
    2. org.jboss.modules.Main.main(Main.java:455)
    2 frames