Java Mail: NoClassDefFoundError: javax/activation/DataSource



我编写了一个小Java命令行程序,以测试从远程服务器发送电子邮件。我得到了可怕的" Noclassdeffounderror",我不知道为什么。

服务器正在运行:

  • Sunos 5.10通用2005年1月
  • Java 1.5.0_30-B03(Sun,Standard)

我的Java程序称为

sendemailacme

错误消息是

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource

程序运行的完整输出是:

bash-3.00$ javac SendEmailACME.java
bash-3.00$ java SendEmailACME
SendEmailACME: Classpath: .:/users/steve/TestProgramsLib/mail.jar:users/steve/TestProgramsLib/activation.jar
DEBUG: setDebug: JavaMail version 1.4.4
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
        at SendEmailACME.main(SendEmailACME.java:47)
bash-3.00$ 

我运行

java -verbose sendemailacme

OUPUT对于堆叠量太长。其中只包括常规输出,以及有关Java加载其所有常规库的一堆消息,来自mail.jar的库,但我没有从javax.activation中看到任何库。*

从" $ echo $ classpath"输出IS:

bash-3.00$ echo $CLASSPATH
.:/users/steve/TestProgramsLib/mail.jar:users/steve/TestProgramsLib/activation.jar
bash-3.00$

我的主目录是

/users/steve

它包含这两个目录

  1. TestPrograms
  2. TestProgramslib

第一个有我的程序sendemailacme.java,sendemailacme.class/第二个有以下罐子:

bash-3.00$ ls -l
total 1102
-rw-r--r--   1 steve  acme      55932 Apr 19  2006 activation.jar
-rw-r--r--   1 steve  acme     494975 Jan 14  2011 mail.jar
bash-3.00$

这是我的命令行程序sendemailacme的源代码:

import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import java.util.Properties;
public class SendEmailACME {

    public static void main(String[] args) throws Exception{

        String smtpServer  = "msg.abc.acme.com";
        int port           = 25;        
        String userid      = "acme.staffdirectory"; 
        String password    = "password";  
        String contentType = "text/html";
        String subject     = "test: Send An Email, From A Java Client Using msg.abc.acme.com";
        String from        = "ACME.Staff.Directory@acme.com";
        String to          = "steve@acme.com,joerre123@gmail.com,fake.mail@acme.com,bogus@fauxmail.com";
        String body        = "<h1>Test. An Email, From A Java Client Using msg.abc.acme.com.</hi>";
        System.out.println("SendEmailACME: Classpath: " + System.getProperty("java.class.path"));
        Properties props   = new Properties();
        props.put("mail.transport.protocol", "smtp");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable","true");
        props.put("mail.smtp.host", smtpServer);
        Session mailSession = Session.getInstance(props);
        // Get runtime more runtime output when attempting to send an email
        mailSession.setDebug(true);
        MimeMessage message = new MimeMessage(mailSession);
        message.setFrom(new InternetAddress(from));
        message.setRecipients(Message.RecipientType.TO, to);
        message.setSubject(subject);
        message.setContent(body,contentType);
        Transport transport = mailSession.getTransport();
        transport.connect(smtpServer, port, userid, password);
        transport.sendMessage(message,message.getRecipients(Message.RecipientType.TO));
        transport.close();
    }// end function main()
}// end class SendEmailACME

这是运行命令的输出,以查看激活中的内容:

bash-3.00$ jar -tf activation.jar
META-INF/MANIFEST.MF
META-INF/SUN_MICR.SF
META-INF/SUN_MICR.RSA
META-INF/
META-INF/mailcap.default
META-INF/mimetypes.default
javax/
javax/activation/
javax/activation/ActivationDataFlavor.class
javax/activation/MimeType.class
javax/activation/MimeTypeParameterList.class
javax/activation/MimeTypeParseException.class
javax/activation/CommandInfo.class
javax/activation/DataHandler$1.class
javax/activation/DataHandler.class
javax/activation/DataSource.class
javax/activation/CommandMap.class
javax/activation/DataContentHandler.class
javax/activation/DataContentHandlerFactory.class
javax/activation/CommandObject.class
javax/activation/DataHandlerDataSource.class
javax/activation/DataSourceDataContentHandler.class
javax/activation/ObjectDataContentHandler.class
javax/activation/FileDataSource.class
javax/activation/FileTypeMap.class
javax/activation/MailcapCommandMap.class
javax/activation/MimetypesFileTypeMap.class
javax/activation/SecuritySupport$1.class
javax/activation/SecuritySupport$2.class
javax/activation/SecuritySupport$3.class
javax/activation/SecuritySupport$4.class
javax/activation/SecuritySupport$5.class
javax/activation/SecuritySupport.class
javax/activation/URLDataSource.class
javax/activation/UnsupportedDataTypeException.class
com/
com/sun/
com/sun/activation/
com/sun/activation/registries/
com/sun/activation/registries/MailcapFile.class
com/sun/activation/registries/MailcapParseException.class
com/sun/activation/registries/MimeTypeFile.class
com/sun/activation/registries/MimeTypeEntry.class
com/sun/activation/registries/LineTokenizer.class
com/sun/activation/registries/LogSupport.class
com/sun/activation/registries/MailcapTokenizer.class
com/sun/activation/viewers/
com/sun/activation/viewers/ImageViewer.class
com/sun/activation/viewers/ImageViewerCanvas.class
com/sun/activation/viewers/TextEditor.class
com/sun/activation/viewers/TextViewer.class
bash-3.00$

一切都很好地编译了,但是似乎无法找到Javax.activation.datasource。

我无法访问jdk_home/jre/lib/ext目录。

我一直在尝试从我的目录执行sendemailacme/用户/Steve/testprograms

事先感谢您的任何帮助

Steve

bash-3.00$ echo $CLASSPATH
.:/users/steve/TestProgramsLib/mail.jar:users/steve/TestProgramsLib/activation.jar

您似乎缺少mail.jar:users/steve之间的/。这意味着java正在寻找activation.jar的错误位置(在./users而不是/users中)。

您的class路径不包含放置javax的jdk库。*放置了库。

相关内容

  • 没有找到相关文章