Java之JavaMail 版本(class冲突问题)

当使用过时的JavaMail库时,可能会与JavaEE中的库发生冲突。推荐使用Maven仓库中的com.sun.mail:javax.mail版本,以避免冲突。javax.mail-api提供了API定义,适合编译,而com.sun.mail:javax.mail包含了实现,包括SMTP、IMAP和POP3协议提供者。在编译和部署时,应选择合适的方式使用这两个依赖。
Maven 上有多个 JavaMail 的库。到底用哪个呢?

[b]一、问题:[/b]
如果下载过时的库,会有与 javaee 中的库冲突的问题。


[b]二、结论:[/b]
使用这个: https://mvnrepository.com/artifact/com.sun.mail/javax.mail


<!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
</dependency>



[b]三、说明:[/b]

[b]JavaMail API from Maven[/b]

[quote]
I am trying to upgrade to latest Java Mail utility.

From

<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>


to (my Intention)

<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.5.1</version>
</dependency>

But I don't find 1.5.1 for mail artifact,

but I can see

<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.1</version>
</dependency>

My Question is why group id changed and if I change the group id for 1.5.1 do I need to change all my mail implementation that is already present (package name change and any other stuff) and what is the difference between com.sun.mail vs javax.mail?

[/quote]


[quote]

The Maven coordinates changed some time ago to be compatible with the scheme described [url=https://glassfish.java.net/wiki-archive/Maven%20Versioning%20Rules.html]here[/url].
The new coordinates are [url=https://java.net/projects/javamail/pages/Home]here[/url].

[b]In short:[/b]

- The groupId [i][color=blue]javax.mail[/color][/i] is no longer used for the implementation.

- There is a new artifact at [i][color=blue]javax.mail:javax.mail-api[/color][/i].
It provides the [i][color=green]javax.mail-api.jar[/color][/i] file. This contains the JavaMail API definitions only, suitable for compiling against.

- [i][color=blue]com.sun.mail:javax.mail[/color][/i] contains the [i][color=green]javax.mail.jar[/color][/i] file, the JavaMail reference implementation jar file,
including the SMTP, IMAP, and POP3 protocol providers.


[b]So, you should:[/b]
- either use [i][color=blue]com.sun.mail:javax.mail[/color][/i] for compilation and packaging/deploy;
- or use [i][color=blue]javax.mail:javax.mail-api[/color][/i] for compilation and
then deploy the [i][color=blue]com.sun.mail:javax.mail[/color][/i] jar where appropriate (e.g., your Tomcat lib).

[/quote]


引用:

http://stackoverflow.com/a/22021656/2893073

https://java.net/projects/javamail/pages/Home


-
转载请注明
原文出处:http://lixh1986.iteye.com/blog/2323537


-
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值