JavaMail jar名称会导致JAF异常吗?

时间:2011-03-04 15:52:34

标签: java classpath javamail

我在其中一个项目中遇到了一个奇怪的问题。由于我们切换到使用Apache Ivy来管理构建依赖项,我们现在部署名为mail-1.4.4.jar的jar而不是之前的mail.jar

使用版本化的jar,我们得到一个堆栈跟踪(见下文)。如果我使用相同的jar并且手动将其重命名为mail.jar,则邮件将成功发送。似乎某种类型的路径问题,JAF无法找到邮件组件类,但我很难解决如何解决根问题,而不是像配置构建来重命名jar这样的创可贴解决方案。

失败堆栈跟踪:

javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
        boundary="----=_Part_0_522583802.1299253374905"
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1141)
        at javax.mail.Transport.send0(Transport.java:195)
        at javax.mail.Transport.send(Transport.java:124)
        at com.rbccm.core.util.MailUtil.sendMail(MailUtil.java:91)
        at com.rbccm.core.util.MailUtil.sendWithAttachment(MailUtil.java:59)
        at com.rbccm.core.util.MailUtil.sendWithAttachment(MailUtil.java:36)
        at com.rbccm.core.util.MailTask$Command$1.execute(MailTask.java:88)
        at com.rbccm.core.util.MailTask$Command$1.execute(MailTask.java:83)
        at com.rbccm.core.util.BatchTask.execute(BatchTask.java:31)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:357)
        at org.apache.tools.ant.Target.performTasks(Target.java:385)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
        at org.apache.tools.ant.Main.runBuild(Main.java:758)
        at org.apache.tools.ant.Main.startAnt(Main.java:217)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
        boundary="----=_Part_0_522583802.1299253374905"
        at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:877)
        at javax.activation.DataHandler.writeTo(DataHandler.java:302)
        at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)
        at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1772)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1099)
        ... 25 more

java -version输出:

java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)

1 个答案:

答案 0 :(得分:0)

这听起来像是一个类路径问题。可以使用包含mail.jar的类路径设置Java Activation Framework。这可以解释为什么当您将mail-1.4.4.jar重命名为mail.jar时它会起作用。

确保您的JAF和Java Mail API jar兼容,然后相应地更新类路径。