[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Sending Email with Javamail doesn't work with J2EE 1.4 Final

Posted on 2003-12-10
4
Medium Priority
?
1,026 Views
Last Modified: 2013-11-24
I'm trying to upgrade from J2EE 1.4 Beta 2 to 1.4 Final. When I run a JUnit test that sends e-mail, I get the following error. This worked fine on Beta 2 - and still does if I switch to point to that j2ee.jar in my classpath. It even worked fine on J2EE 1.3.  

Platform: JDK 1.4.2, Windows XP

===============================================================

[junit] Testcase: testSendTextMessage(org.appfuse.common.util.MailUtilTest): Caused an EROR
[junit] com/sun/mail/util/SharedByteArrayInputStream
[junit] java.lang.NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream
[junit] at org.appfuse.common.util.MailUtil.sendMessage(MailUtil.java:77)
[junit] at org.appfuse.common.util.MailUtil.sendTextMessage(MailUtil.java:151)
[junit] at org.appfuse.common.util.MailUtilTest.testSendTextMessage(MailUtilTest.java:59)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

===============================================================

I'm certainly not importing this class:

===============================================================

package org.appfuse.common.util;

import org.apache.commons.lang.StringUtils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.appfuse.common.Constants;

import java.util.Properties;
import java.util.ResourceBundle;

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;

import javax.naming.InitialContext;
import javax.naming.NamingException;

public class MailUtil extends Object {

===============================================================

But it does look like a classpath conflict or something??

Here is the offending line of code (MailUtil: 77):

===============================================================

Message message = new MimeMessage(getSession());

Where the getSession() method is:

===============================================================
    public static Session getSession() {
        Session session = null;

        try {
            session =
                (Session) new InitialContext().lookup("java:comp/env/" +
                                                      Constants.JNDI_MAIL);
        } catch (NamingException ex) {
            if (log.isDebugEnabled()) {
                log.info("error communicating with JNDI, assuming testcase");
            }

            ResourceBundle mailProps = ResourceBundle.getBundle("mail");

            Properties props = new Properties();
            props.setProperty("mail.debug", mailProps.getString("mail.debug"));
            props.setProperty("mail.transport.protocol",
                              mailProps.getString("mail.transport.protocol"));
            props.setProperty("mail.host", mailProps.getString("mail.host"));
            props.setProperty("mail.user", mailProps.getString("mail.user"));
            props.setProperty("mail.password",
                              mailProps.getString("mail.password"));
            session = Session.getDefaultInstance(props, null);
        }

        return session;
    }

===============================================================
Any help is greatly appreciated.

Matt
0
Comment
Question by:mraible
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 9916691
appears it could be a class conflict.
what is in your classpath and ext directory?
0
 
LVL 1

Author Comment

by:mraible
ID: 9947409
I changed from using j2ee.jar in my classpath to activation.jar and mail.jar and this fixed the problem.  
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question