Vaadin ServletException:无法加载应用程序类

时间:2012-12-18 08:54:18

标签: java exception servlets vaadin

当我尝试通过localhost / testVaadin /

在浏览器中加载servlet时,我有一个vaadin和servlet错误

我想执行此示例以了解vaadin的工作原理,因为我必须使用活动资源管理器实现BPMN,它使用vaadin作为UI框架。

我附加了代码,web.xml和抛出的异常。

package com.example.testvaadin;

import com.vaadin.Application;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

我的班级

public class SimpleAddressBook extends Application {

变量

private static String[] fields = { "First Name", "Last Name", "Company",
        "Mobile Phone", "Work Phone", "Home Phone", "Work Email",
        "Home Email", "Street", "Zip", "City", "State", "Country" };
private static String[] visibleCols = new String[] { "Last Name",
        "First Name", "Company" };


private Table contactList = new Table();
private Form contactEditor = new Form();
private HorizontalLayout bottomLeftCorner = new HorizontalLayout();
private Button contactRemovalButton;
private IndexedContainer addressBookData = createDummyData();

功能

@Override
public void init() {
    initLayout();
    initContactAddRemoveButtons();
    initAddressList();
    initFilteringControls();
}

private void initLayout() {
    HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
    setMainWindow(new Window("Address Book", splitPanel));
    VerticalLayout left = new VerticalLayout();
    left.setSizeFull();
    left.addComponent(contactList);
    contactList.setSizeFull();
    left.setExpandRatio(contactList, 1);
    splitPanel.addComponent(left);
    splitPanel.addComponent(contactEditor);
    contactEditor.setCaption("Contact details editor");
    contactEditor.setSizeFull();
    contactEditor.getLayout().setMargin(true);
    contactEditor.setImmediate(true);
    bottomLeftCorner.setWidth("100%");
    left.addComponent(bottomLeftCorner);
}

private void initContactAddRemoveButtons() {
    // New item button
    bottomLeftCorner.addComponent(new Button("+",
            new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    // Add new contact "John Doe" as the first item
                    Object id = ((IndexedContainer) contactList
                            .getContainerDataSource()).addItemAt(0);
                    contactList.getItem(id).getItemProperty("First Name")
                            .setValue("John");
                    contactList.getItem(id).getItemProperty("Last Name")
                            .setValue("Doe");

                    // Select the newly added item and scroll to the item
                    contactList.setValue(id);
                    contactList.setCurrentPageFirstItemId(id);
                }
            }));

    // Remove item button
    contactRemovalButton = new Button("-", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            contactList.removeItem(contactList.getValue());
            contactList.select(null);
        }
    });
    contactRemovalButton.setVisible(false);
    bottomLeftCorner.addComponent(contactRemovalButton);
}

private void initAddressList() {
    contactList.setContainerDataSource(addressBookData);
    contactList.setVisibleColumns(visibleCols);
    contactList.setSelectable(true);
    contactList.setImmediate(true);
    contactList.addListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            Object id = contactList.getValue();
            contactEditor.setItemDataSource(id == null ? null : contactList
                    .getItem(id));
            contactRemovalButton.setVisible(id != null);
        }
    });
}

private void initFilteringControls() {
    for (final String pn : visibleCols) {
        final TextField sf = new TextField();
        bottomLeftCorner.addComponent(sf);
        sf.setWidth("100%");
        sf.setInputPrompt(pn);
        sf.setImmediate(true);
        bottomLeftCorner.setExpandRatio(sf, 1);
        sf.addListener(new Property.ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                addressBookData.removeContainerFilters(pn);
                if (sf.toString().length() > 0 && !pn.equals(sf.toString())) {
                    addressBookData.addContainerFilter(pn, sf.toString(),
                            true, false);
                }
                getMainWindow().showNotification(
                        "" + addressBookData.size() + " matches found");
            }
        });
    }
}

private static IndexedContainer createDummyData() {

    String[] fnames = { "Peter", "Alice", "Joshua", "Mike", "Olivia",
            "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene",
            "Lisa", "Marge" };
    String[] lnames = { "Smith", "Gordon", "Simpson", "Brown", "Clavel",
            "Simons", "Verne", "Scott", "Allison", "Gates", "Rowling",
            "Barks", "Ross", "Schneider", "Tate" };

    IndexedContainer ic = new IndexedContainer();

    for (String p : fields) {
        ic.addContainerProperty(p, String.class, "");
    }

    // Create dummy data by randomly combining first and last names
    for (int i = 0; i < 1000; i++) {
        Object id = ic.addItem();
        ic.getContainerProperty(id, "First Name").setValue(
                fnames[(int) (fnames.length * Math.random())]);
        ic.getContainerProperty(id, "Last Name").setValue(
                lnames[(int) (lnames.length * Math.random())]);
    }

    return ic;
}

}

这是java部分

并且web.xml是

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>testVaadin</display-name>
<context-param>
    <description>
    Vaadin production mode</description>
    <param-name>productionMode</param-name>
    <param-value>false</param-value>
</context-param>
<servlet>
    <servlet-name>Testvaadin Application</servlet-name>
    <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
    <init-param>
        <description>
        Vaadin application class to start</description>
        <param-name>application</param-name>
        <param-value>com.example.testvaadin.SimpleAddressBook</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>Testvaadin Application</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

我使用tomcat作为webserver(6.0.32)

所以错误是:

  

rg.apache.catalina.core.StandardWrapperValve调用GRAVE:Exception lors de l&#39; allocation pour la servlet Testvaadin Application javax.servlet.ServletException:无法加载应用程序类:com.example.testvaadin.SimpleAddressBook at com。 vaadin.terminal.gwt.server.ApplicationServlet.init(ApplicationServlet.java:71)atg.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:809)org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atg.apache.catalina .core.StandardHostValve.invoke(StandardHostValve.java:127)org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109 )org.ap上的org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) ache.coyote.http11.Http11Processor.process(Http11Processor.java:859)org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:588)at org.apache.tomcat.util.net.JIoEndpoint $ java.lang.Thread.run上的Worker.run(JIoEndpoint.java:489)(Thread.java:662)

1 个答案:

答案 0 :(得分:1)

基本上,错误消息是com.vaadin.terminal.gwt.server.ApplicationServlet在初始化期间尝试加载com.example.testvaadin.SimpleAddressBook但未成功。

要解决此问题,请尝试以下操作:

  • 检查应用程序部署是否成功,并且类SimpleAddressBook确实位于servlet容器中的正确位置
  • 检查WEB-INF / lib中是否有vaadin-xx.yy.zz.jar
  • 清理并重建整个项目