Netbeans: how to add Java EE container to java project

后端 未结 1 1134
自闭症患者
自闭症患者 2021-01-21 13:06

I am trying to send am email SSL email in Netbeans and I have added both javaee.jar and mail.jar to my project but I am getting the following error

相关标签:
1条回答
  • 2021-01-21 13:43

    how to add Java EE container to java project

    No, please don't do that. Your sole intent seems to run a Java SE (desktop) application, not a Java EE (web) application. You should not run a Java SE application as a Java EE application.

    You should rather find the right solution for the concrete problem you're facing instead of asking how to achieve the wrong solution.

    As to your concrete problem,

    Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException

    This basically means that the mentioned class (the javax/mail/MessagingException) in the current runtime classpath only contains the class and method signatures, but no concrete code at all. In other words, the mentioned class in the current runtime classpath is empty. And indeed, the javaee.jar which you've there (apparently you downloaded it in a wrong attempt to solve compile/import problems) contains basically the abstract Java EE API without any concrete implementation code.

    This is not right. Remove that javaee.jar file altogether. Just the mail.jar which you can download from JavaMail website is sufficient. Your concrete problem is caused because the javaee.jar file, which also contains the javax.mail API (but without implementation), got precedence in classloading over mail.jar file which contains the concrete javax.mail implementation. The javaee.jar file should only be used as a compiletime dependency in Java EE projects, not as a runtime dependency of Java SE projects.

    0 讨论(0)
提交回复
热议问题