Strange compile problem with javax.mail

  • Thread starter Andreas Wollschlaeger
  • Start date
A

Andreas Wollschlaeger

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
 
G

GaryM

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
 
A

Andreas Wollschlaeger

GaryM said:
<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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top