Error: Unable to initialize main class AirMail Caused by: java.lang.NoClassDefFoundError: javax/mail/Authenticator

huangapple go评论76阅读模式
英文:

Error: Unable to initialize main class AirMail Caused by: java.lang.NoClassDefFoundError: javax/mail/Authenticator

问题

我正在创建一个使用Swing、AWT和邮件API的Java应用程序,它的名字是AirMail。它具有发送电子邮件的功能,包括附加文件的功能,该电子邮件服务由Gmail(谷歌)提供。

我已经在命令行上使用jar -cvmf manifest.mf AirMail.jar命令创建了它的jar文件。因此,当我启动jar文件时,出现了一个错误。
错误信息:

无法初始化主类 AirMail Caused by: java.lang.NoClassDefFoundError: javax/mail/Authenticator

正如上面的错误所说,在javax/mail/Authenticator中出现了NoClassDefFoundError。我检查了Mail API中是否存在javax/mail/Authenticator类,是的,它存在。

通常,我们需要在manifest.mf文件中提供Main-Class的值,我已经检查了我的Manifest.mf文件,并在其中添加了Main-Class的值,此外我在Manifest.mf文件的末尾已经留了一行空白行。

Manifest.mf文件的内容

  • Manifest-Version: 1.0
  • Created-By: 11.0.7 (Oracle Corporation)
  • Main-Class: AirMail

我提供了一个链接,链接到我的AirMail.java代码。

https://github.com/thesumitsuryawanshi/Air-Mail/blob/master/AirMail.java

我正在使用Ubuntu 18.04 64位操作系统。

任何帮助!或者关于我的问题的额外知识将不胜感激!谢谢!

英文:

I am creating a Java Application with Swing , AWT and Mail API whose name is AirMail.
Which Sends Email with a featuer of attaching file and this email service is provided by Gmail (Google).

I have created its jar file on command line by jar -cvmf manifest.mf AirMail.jar command .
So , I'm getting an error when I, launch jar file.
Error :

Unable to initialize main class AirMail Caused by: java.lang.NoClassDefFoundError: javax/mail/Authenticator

As, above error says NoClassDefFoundError in javax/mail/Authenticator .
I check out , javax/mail/Authenticator class is present or not in the Mail API.
and , Yes It is Present.

Usually, we need to provide Main-Class value in manifest.mf file and I have checked my Manifest.mf file and added its Main-Class value along with this Ive already left a blank line at the end of Manifest.mf file.

Content of Manifest.mf file

  • Manifest-Version: 1.0
  • Created-By: 11.0.7 (Oracle Corporation)
  • Main-Class: AirMail

I'm Providing a link to my AirMail.java code.

https://github.com/thesumitsuryawanshi/Air-Mail/blob/master/AirMail.java

I'm using Ubuntu 18.04 "64-bit"

Any Help !!
or
Extra Knowledge about my question would be appreciated.!!
Thank you !!

答案1

得分: 1

据我所知,javax.mail包似乎不包含在Java 11中。您需要将其作为项目的依赖项添加。

对于Maven项目,可以尝试以下配置:

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

AFIK javax.mail package is not part of Java 11. you need to add this as a dependency to your project.

for maven this could work

&lt;!-- https://mvnrepository.com/artifact/com.sun.mail/javax.mail --&gt;
&lt;dependency&gt;
    &lt;groupId&gt;com.sun.mail&lt;/groupId&gt;
    &lt;artifactId&gt;javax.mail&lt;/artifactId&gt;
    &lt;version&gt;1.6.2&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年8月21日 03:05:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63511675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定