NoClassDefFoundError: javax/activation/DataSource

2020-07-01 07:10发布

This is the code :

      Session session = Session.getDefaultInstance(props, null);
      Store store = session.getStore("imaps");
      store.connect("imap.gmail.com", "****@gmail.com", "****");
      System.out.println(store);
      Folder folder = store.getDefaultFolder();
      folder = folder.getFolder("INBOX");
      folder.open(Folder.READ_ONLY);

      System.out.println("Message Count: "+folder.getMessageCount());
      System.out.println("Unread Message Count: "+folder.getUnreadMessageCount());


           Message[] messages = folder.getMessages();  --> here the code stops.

      FetchProfile fp = new FetchProfile();
      fp.add(FetchProfile.Item.ENVELOPE);
      folder.fetch(messages, fp);

      for (int i = 0; i< messages.length; i++) 
      { 
          System.out.println("From:"+ messages[i].getFrom()); 
          }

The code gives out the following excption and stops at the point shown.

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource at com.google.code.com.sun.mail.imap.MessageCache.getMessage(MessageCache.java:129) at com.google.code.com.sun.mail.imap.IMAPFolder.getMessage(IMAPFolder.java:1394) at openReports.OpenReports.main

标签: java javamail
3条回答
三岁会撩人
2楼-- · 2020-07-01 07:40

I added activation.jar to buildpath and the problem is solved.

So i used 2 jars java-mail-ima.** .jar, activation.jar (for further referebces).

查看更多
不美不萌又怎样
3楼-- · 2020-07-01 07:42

In case you use maven you can add manually

<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>
查看更多
Animai°情兽
4楼-- · 2020-07-01 07:54

I solved a similar NoClassDefFoundError: javax/activation/DataSource problem in a mixed Java/Scala project by switching to Java 8 (it was Java9 by default).

Discussion: https://github.com/highsource/jsonix-schema-compiler/issues/81

查看更多
登录 后发表回答