且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Netbeans:如何将 Java EE 容器添加到 java 项目

更新时间:2023-12-03 13:49:40

如何将 Java EE 容器添加到 java 项目中

不,请不要那样做.您的唯一意图似乎是运行 Java SE(桌面)应用程序,而不是 Java EE(Web)应用程序.您不应将 Java SE 应用程序作为 Java EE 应用程序运行.

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.

至于你的具体问题,

线程main"java.lang.ClassFormatError 中的异常:类文件 javax/mail/MessagingException 中非本机或抽象方法中的缺失代码属性

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

这基本上意味着当前运行时类路径中提到的类(javax/mail/MessagingException)包含类和方法签名,但没有具体代码全部.换句话说,当前运行时类路径中提到的类是empty.事实上,您所拥有的 javaee.jar(显然您下载它是为了解决编译/导入问题的错误尝试)基本上包含抽象的 Java EE API 没有任何具体的实现代码.

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.

这是不对的.删除javaee.jar 文件.只需从 JavaMail 下载的 mail.jar网站 就足够了.您的具体问题是由于 包含 javax.mail API(但没有实现)的 javaee.jar 文件优先于通过包含具体 javax.mail 实现的 mail.jar 文件进行类加载.javaee.jar 文件只能用作 Java EE 项目中的编译时依赖项,而不应用作 Java SE 项目的运行时依赖项.

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.