java - ClassNotFoundException : org. eclipse.swt.widgets.Display

标签 java eclipse jsp outlook swt

我需要创建一个带有按钮的 jsp 页面 - 单击该按钮后,它将在 Outlook 中打开“新电子邮件”窗口,其中填充了“收件人”、“主题”和“正文”字段。

我通过 servlet 实现此功能,因此当用户单击按钮时,将调用 servlet,并从 servlet 类的 doGet() 调用以下代码。

当我尝试将其作为独立的 java 应用程序进行测试时,效果很好,并且新的消息窗口完美打开。但是当我尝试通过 jsp 表单打开它时,出现异常。

异常:

java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Display

我已经包含了以下 jar :

org.eclipse.swt.win32.win32.x86_3.7.0.v3735b.jar
org.eclipse.core.commands_3.6.0.I20110111-0800.jar

代码引用自:http://www.vogella.com/tutorials/EclipseMicrosoftIntegration/article.html

代码:

Display display = Display.getCurrent();
Shell shell = new Shell(display);
OleFrame frame = new OleFrame(shell, SWT.NONE);
// This should start outlook if it is not running yet
OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl");
site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
// now get the outlook application
OleClientSite site2 = new OleClientSite(frame, SWT.NONE,"Outlook.Application");
OleAutomation outlook = new OleAutomation(site2);
OleAutomation mail = invoke(outlook, "CreateItem", 0 /* Mail item */)
        .getAutomation();
setProperty(mail, "To", "someone@something.com"); /*
                           * Empty but could also be
                           * predefined
                           */
// setProperty(mail, "Bcc", "test@gmail.com"); 
/*
                           * Empty but could also be
                           * predefined
                           */
setProperty(mail, "BodyFormat", 2 /* HTML */);
setProperty(mail, "Subject", "Top News for you");
        setProperty(mail, "HtmlBody",
            "some message");
//      File file = new File("c:/temp/test.txt");
//      if (file.exists()) {
//        OleAutomation attachments = getProperty(mail, "Attachments");
//        invoke(attachments, "Add", "c:/temp/test.txt");
//      } else {
//        MessageDialog
//            .openInformation(shell, "Info",
//                "Attachment File c:/temp/test.txt not found; will send email with attachment");
//      }
invoke(mail, "Display" /* or "Send" */);

最佳答案

当您在java的Web应用程序中使用jar时,您已将jar文件放在项目的lib文件夹中。所以请确保你这样做。

关于java - ClassNotFoundException : org. eclipse.swt.widgets.Display,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22473833/

相关文章:

java - 应用程序崩溃并且不显示 Toast 消息

java - Java 中的类型安全方法反射

java - 从java main方法调用servlet

java - java-ee中if语句的逻辑问题

java - 逐行读取时如何打印上一行和下一行以比较字符串

java - 连续两次调用 Buffer.flip() 有问题吗?

java - 我们可以在eclipse中从我们的项目中调用另一个项目java类吗

eclipse - 导入 PMD Eclipse 规则

java.lang.UnsatisfiedLinkError : no opencv_java2411 in java. 库路径

java - SEO URL 重写不起作用