Netbeans: how to add Java EE container to java project

£可爱£侵袭症+ 提交于 2019-12-02 01:26:05

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!