Unable to import javax.activation in Jdeveloper for MAF
Asked Answered
N

0

0

I am trying to deploy an Oracle MAF app to the iOS platform. I am using Java Mail to receive emails from the gmail server. I am trying to to identify mails that have attachments. However I get the following error.

java.lang.ClassCastException: com.sun.mail.imap.IMAPInputStream cannot be cast to javax.mail.Multipart

When I identify the mime type of the message as "multipart/mixed", I am trying to cast the object into Multipart.

I understand that this question has been asked before but I have tried to implement the solution proposed here. However I am unable to import anything from javax.activation. The error that I get in jdeveloper is

Error : javax.activation.CommandMap is not available in the profile.

This error shows up for everything from javax.activation

Also, this error pops up only in an MAF application. It works well in a normal java project.

How can I handle this issue?

import java.util.Properties;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Store;

public class Email {
    public Email() 
    {

        String userName = "[email protected]";
        String password = "password";
        String receivingHost;

        receivingHost="imap.gmail.com";

        Properties props=System.getProperties();
        props.setProperty("mail.store.protocol", "imaps");

        Session session=Session.getDefaultInstance(props, null);

        try 
        {
             Store store=session.getStore("imaps");
             store.connect(receivingHost,userName, password);
             Folder folder=store.getFolder("INBOX");
             folder.open(Folder.READ_ONLY);
             Message messages[]=folder.getMessages();

             //System.out.println(messages.length);
             for (Message message : messages) 
             {
                 if(message.isMimeType("multipart/mixed")) 
                 {
                     Multipart mp = (Multipart)message.getContent();
                     //get content    
                 }
                 else 
                 {
                    //getcontent
                 }
             }

             store.close();

        }
        catch (Exception e) 
        {
            System.out.println(e.toString());
        }
        //System.out.println("Done");
    }
}
Nephrotomy answered 18/7, 2016 at 12:19 Comment(4)
How are you including JavaMail in your application? Are you including the JavaMail jar file or are you extracting the classes from the jar file and just including the classes? The latter won't work unless you also include the config files in META-INF. I don't know why JDeveloper won't let you import javax.activation; what version of the JDK are you using?Beefsteak
@BillShannon Thanks for the response. I am importing the java mail jar and the activation jar using the project properties->Libraries and classpath. I am using JDK 8Nephrotomy
I really don't know anything about JDeveloper but javax.activation is part of JDK 8 so if it won't let you import it without doing anything special, JDeveloper is broken and you should file a bug against it.Beefsteak
Importing the jar file probably tells JDeveloper to package it in your application (the common case) so you need to find a way to tell it to use the jar file for compiling but not package it with your application. Maybe if you can just tell it that you're developing a Java EE application it will handle this for you?Beefsteak

© 2022 - 2024 — McMap. All rights reserved.