java.lang.NoClassDefFoundError

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
tip

Check if the version of resteasy is using is the same JBoss is using. To find it out, search for resteasy-jaxrs* in JBoss/Wildfly directory and at your pom.xml.

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • 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}
    via by Agustin Treceno,
  • Vraptor 3 - Hibernate 4
    via by Unknown author,
  • Vraptor 3 - Hibernate 4 - Front-end - GUJ
    via by Unknown author,
    • 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

    Users with the same issue

    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Andreas Häber
    1 times, last one,
    81 more bugmates