Java GMail api - java.lang.VerifyError: Cannot inherit from final class
Java GMail api - java.lang.VerifyError: Cannot inherit from final class
我将 glassfish server 4.1 与 java JDK 1.8 一起使用。我使用 maven 来构建和部署。
我制作了一个表单,触发控制器使用 gmail api 发送电子邮件。
触发控制器的形式:
<form method="post" action=GmailController>
<td>Test API gmail</td>
<td><input name="email" value="${requestScope.get("email")}" /></td>
<td><input type="submit" value="Send email" /></td>
</form>
控制器"GmailController":
@WebServlet("/GmailController")
public class GmailController extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String email = request.getParameter("email");
try {
sendAnEmail("email_body", email, email); //custom method that uses gmail API
} catch (Exception e) {
e.printStackTrace();
}
}
}
调用GMailAPI函数的sendAnEmail方法:
public static void sendAnEmail(String body, String from, String to) throws Exception {
Gmail service = getGmailService();
MimeMessage msg = createEmail(to, from, "Area", body);
sendMessage(service, "email@example.com", msg);
}
当我提交触发控制器的表单时,我收到 HTTP 500 错误并且 glassfish 显示:
java.lang.VerifyError: Cannot inherit from final class
当我在我的 java glassfish 网络应用程序之外测试 GMail API 时,它通过在 java 主程序中调用 sendAnEmail
正常工作。
我不明白是什么导致了这个错误,因为我的 class 没有继承任何其他 class,除了 HttpServlet
。
当我评论 sendAnEmail()
调用时,没有错误,所以错误一定不是因为 HttpServlet
继承。
是什么导致了这个错误?
我如何调试或获取有关它的更多信息?
在 server.log 中我没有得到更多信息,它显示相同的错误并告诉线程已停止。
经过一些测试,另一台计算机上的代码与 OS 完全相同:
java.lang.NoSuchMethodError: com.google.api.client.util.ClassInfo.getFieldInfos()Ljava/util/Collection;
相反。
google-api-services-oauth2,google-api-services-gmail 和 google-api-client都是1.23.0版本。
错误:java.lang.VerifyError: Cannot inherit from final class
基于此 thread,您成功创建了一个 class 扩展了一个 superclass,其中 superclass 已被声明为 final
.
The most likely cause is that you have a conflict between your build classpath and your launch classpath. In other words, you are compiling your subclass against a version of the superclass that is not final
, and then running against a version that is final
. The verifier is saying (correctly) that this is wrong.
错误:java.lang.NoSuchMethodError: com.google.api.client.util.ClassInfo.getFieldInfos()Ljava/util/Collection;
基于此 forum,您的代码正在(间接)调用一个不存在的方法。检查您在 class 路径中使用的依赖项。
希望对您有所帮助!
我将 glassfish server 4.1 与 java JDK 1.8 一起使用。我使用 maven 来构建和部署。
我制作了一个表单,触发控制器使用 gmail api 发送电子邮件。
触发控制器的形式:
<form method="post" action=GmailController>
<td>Test API gmail</td>
<td><input name="email" value="${requestScope.get("email")}" /></td>
<td><input type="submit" value="Send email" /></td>
</form>
控制器"GmailController":
@WebServlet("/GmailController")
public class GmailController extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String email = request.getParameter("email");
try {
sendAnEmail("email_body", email, email); //custom method that uses gmail API
} catch (Exception e) {
e.printStackTrace();
}
}
}
调用GMailAPI函数的sendAnEmail方法:
public static void sendAnEmail(String body, String from, String to) throws Exception {
Gmail service = getGmailService();
MimeMessage msg = createEmail(to, from, "Area", body);
sendMessage(service, "email@example.com", msg);
}
当我提交触发控制器的表单时,我收到 HTTP 500 错误并且 glassfish 显示:
java.lang.VerifyError: Cannot inherit from final class
当我在我的 java glassfish 网络应用程序之外测试 GMail API 时,它通过在 java 主程序中调用 sendAnEmail
正常工作。
我不明白是什么导致了这个错误,因为我的 class 没有继承任何其他 class,除了 HttpServlet
。
当我评论 sendAnEmail()
调用时,没有错误,所以错误一定不是因为 HttpServlet
继承。
是什么导致了这个错误? 我如何调试或获取有关它的更多信息?
在 server.log 中我没有得到更多信息,它显示相同的错误并告诉线程已停止。
经过一些测试,另一台计算机上的代码与 OS 完全相同:
java.lang.NoSuchMethodError: com.google.api.client.util.ClassInfo.getFieldInfos()Ljava/util/Collection;
相反。
google-api-services-oauth2,google-api-services-gmail 和 google-api-client都是1.23.0版本。
错误:java.lang.VerifyError: Cannot inherit from final class
基于此 thread,您成功创建了一个 class 扩展了一个 superclass,其中 superclass 已被声明为 final
.
The most likely cause is that you have a conflict between your build classpath and your launch classpath. In other words, you are compiling your subclass against a version of the superclass that is not
final
, and then running against a version that isfinal
. The verifier is saying (correctly) that this is wrong.
错误:java.lang.NoSuchMethodError: com.google.api.client.util.ClassInfo.getFieldInfos()Ljava/util/Collection;
基于此 forum,您的代码正在(间接)调用一个不存在的方法。检查您在 class 路径中使用的依赖项。
希望对您有所帮助!