Strange compile problem with javax.mail

Discussion in 'Java' started by Andreas Wollschlaeger, Jan 29, 2004.

  1. Hi folks,

    i have a strange problem this morning which is just driving me nuts :-/

    I am working on an app, one part is the sending of some email via
    javax.mail! Here is a snippet of code:

    -- snip --

    java.util.Properties p = System.getProperties();
    javax.mail.Session s = javax.mail.Session.getDefaultInstance(p);
    Message m = new MimeMessage(s);
    ...
    Transport t = s.getTransport("smtp");
    t.connect(smtphost, username, password);
    t.sendMessage(m, m.getAllRecipients());
    t.close();

    -- snip --

    Nothing special here! Now the problem: From within Netbeans, this
    compiles and runs perfectly. But, when i launch ant to build the same
    stuff, javac woes:

    Compiling 34 source files to C:\work\ELP_BOT\ELP_BOT\__ELP_BOT\build
    __ELP_BOT\src\com\elpmedien\backorder_tool\MailHelper.java [40]

    getDefaultInstance(java.util.Properties,javax.mail.Authenticator) in
    javax.mail.Session cannot be applied to (java.util.Properties)
    javax.mail.Session s = javax.mail.Session.getDefaultInstance(p);
    ^
    1 error

    The strange thing is, i use the same set of jars both for Netbeans and
    Ant! I also tried updating mail.jar and activation.jar with the current
    version from java.sun.com, same result.

    If i change the invocation of getDefaultInstance() to

    javax.mail.Session s = javax.mail.Session.getDefaultInstance(p,null);

    the code builds, but throws an exception:

    java.lang.NoClassDefFoundError: com/sun/mail/util/MailDateFormat
    at com.elpmedien.backorder_tool.MailHelper.sendMail(Unknown Source)

    Any ideas?

    Cheers
    Andreas
     
    Andreas Wollschlaeger, Jan 29, 2004
    #1
    1. Advertising

  2. Andreas Wollschlaeger

    GaryM Guest

    Andreas Wollschlaeger <postmaster@1.0.0.127.in-addr.arpa> wrote in
    news:bvaqmn$564$04$-online.com:

    > Hi folks, i have a strange problem this morning which is just
    > driving me nuts :-/
    >



    <SNIP>

    Wonder what happens if you simply declare a reference to
    com/sun/mail/util/MailDateFormat in a simple program? Likewise pick
    another class in that lib? I am thinking it's classpath related, but
    I can definitely see why you're frustrated, as everything looks OK.

    As an aside, I was wondering why you were giving the Session your
    System properties. I was concerned there might be an overlap in
    property names. I took a quick look and could not see one.

    Gary
     
    GaryM, Jan 29, 2004
    #2
    1. Advertising

  3. GaryM wrote:
    > Andreas Wollschlaeger <postmaster@1.0.0.127.in-addr.arpa> wrote in
    > news:bvaqmn$564$04$-online.com:
    >
    >
    >>Hi folks, i have a strange problem this morning which is just
    >>driving me nuts :-/
    >>

    >
    >
    >
    > <SNIP>
    >
    > Wonder what happens if you simply declare a reference to
    > com/sun/mail/util/MailDateFormat in a simple program? Likewise pick
    > another class in that lib? I am thinking it's classpath related, but
    > I can definitely see why you're frustrated, as everything looks OK.


    You are right, it was the classpath: When building with ant, a .jar from
    Hibernate (j2ee.jar), containining an older version of javax.mail.*
    sneaked into the classpath. Arghh, javas counterpart to Windows DLL-hell ;-)

    >
    > As an aside, I was wondering why you were giving the Session your
    > System properties. I was concerned there might be an overlap in
    > property names. I took a quick look and could not see one.
    >


    I use this frequently: loading my apps properties into the system
    properties on startup, so i have all properties in one place. Perhaps
    not appropriate for large scale apps, but works for me...

    Cheers
    Andreas
     
    Andreas Wollschlaeger, Jan 29, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    768
    Esmond Pitt
    Mar 27, 2005
  2. lizard
    Replies:
    0
    Views:
    1,785
    lizard
    Jan 30, 2006
  3. Andrew Thompson

    javax.servlet and javax.servlet.http

    Andrew Thompson, Apr 24, 2007, in forum: Java
    Replies:
    1
    Views:
    688
    newbie_at_tomcat
    Apr 25, 2007
  4. hopehope_123

    very strange javax,mail issue

    hopehope_123, Dec 27, 2007, in forum: Java
    Replies:
    3
    Views:
    329
    Roedy Green
    Dec 28, 2007
  5. Laura Schmidt
    Replies:
    13
    Views:
    177
    Lars Enderin
    May 30, 2014
Loading...

Share This Page