java.lang.NoSuchMethodError on Timer thread

I get an error on a timed thread executed from within a servlet.

I am using Tomcat Version 4.0.4, Java version is j2sdk1.5.0_05, and JavaMail version is 1.4.

The servlet's classes and java files are all compiled directly in the servlet web-inf/classess folder.

I have put the mail.jar source in several of the jar-accesing folders appointed in the tomcat docs.

This is the error report:

Exception in thread "Timer-0" java.lang.NoSuchMethodError: javax.mail.internet.MimeBodyPart.saveFile(Ljava/io/File;)V

at MailDaemon.saveAttachment(MailDaemon.java:278)

at MailDaemon.analize(MailDaemon.java:176)

at MailDaemon.run(MailDaemon.java:87)

at java.util.TimerThread.mainLoop(Timer.java:512)

at java.util.TimerThread.run(Timer.java:462)

This is the refered saveAttachment method:

private String saveAttachment(Part message, String folder)throws MessagingException,IOException{

File f;

//Several error-checking lines not shown, as they are not used in case of a properly formatted mail

//both versions yield the same error:

//MimeBodyPart mbp=(MimeBodyPart)message;

//if (mbp instanceof MimeBodyPart)

//mbp.saveFile(f);//this line would cause the same error, too

((MimeBodyPart)message).saveFile(f);//this is line number 278 of MailDaemon.java

}

return filename;

}//end saveAttachment

The javax.mail.internet.MimeBodyPart Documentation (from JavaMail) indicates it has this method:

"public void saveFile(java.io.File file) throws java.io.IOException, MessagingException

Save the contents of this part in the specified file.

The content is decoded and saved, without any of the MIME headers."

As a side note, if the line that causes the error is comented, no other error is reported, except those derived from not having the file properly saved.

The TimerThread is run from the servlet's init() method:

Timer temporizador=new Timer(true);//timer for periodic execution

MailDaemon demonio=new MailDaemon();//mail reading daemon

long first=30000;

long delay=1800000;

temporizador.schedule(demonio,first,delay);

However, when run from a standard stright java program, from its static main method, it works perfectly:

publicstaticvoid main(String[] args)

{

//create Daemon Thread to read mail

Timer temporizador=new Timer(false);//timer for periodic execution

MailDaemon demonio=new MailDaemon();

long delay=30000;

temporizador.schedule(demonio,100,delay);

}

This does not generate any error, and the MailDaemon.java is the same, of course

Any idea on how this error can be solved?

Thanks in advance for your help.

[3773 byte] By [shadowcata] at [2007-11-27 2:19:07]
# 1

> java.lang.NoSuchMethodError: javax.mail.internet.MimeBodyPart.saveFile(

It seems You hava conflicting implementation of javax.mail.internet.MimeBodyPart

and wrong one get loaded first ;((

Check Your packadges and try to change the order of dirs in classpath. Or, even better find the conflict and remove it ;)

Good luck!

_Dima_a at 2007-7-12 2:19:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

> It seems You hava conflicting implementation of javax.mail.internet.MimeBodyPart

> and wrong one get loaded first ;((

> Check Your packadges and try to change the order of

> dirs in classpath. Or, even better find the conflict

> and remove it ;)

> Good luck!

Thanks for the tip, it was an older version of mail.jar which I haven't realized was still around. Once erased (from ...tomcat\common\lib), the error disappeared as it loaded the correct one I had installed in ...\tomcat\lib.

Your help was certainly useful 8)

shadowcata at 2007-7-12 2:19:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...