创建servlet完成后发生错误?

时间:2012-04-20 11:12:43

标签: java tomcat servlets

在Eclipse中创建一个新的Servlet时出现了这个错误:

 java.lang.Error: Unresolved compilation problems: 
The import org.eclipse.jst.j2ee.internal cannot be resolved
CreateServletTemplateModel cannot be resolved to a type
CreateServletTemplateModel cannot be resolved to a type
    at org.eclipse.jst.j2ee.web.ServletTemplate.<init>(ServletTemplate.java:3)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at java.lang.Class.newInstance0(Unknown Source)

at java.lang.Class.newInstance(Unknown Source)

at org.eclipse.emf.codegen.jet.JETEmitter.setMethod(JETEmitter.java:279)

at org.eclipse.jst.j2ee.internal.project.WTPJETEmitter.loadClass(WTPJETEmitter.java:358)

at org.eclipse.jst.j2ee.internal.project.WTPJETEmitter.initialize(WTPJETEmitter.java:231)

at org.eclipse.jst.j2ee.internal.project.WTPJETEmitter.<init>(WTPJETEmitter.java:111)

at org.eclipse.jst.j2ee.internal.web.operations.NewServletClassOperation.generateTemplateSource(NewServletClassOperation.java:351)

at org.eclipse.jst.j2ee.internal.web.operations.NewServletClassOperation.generateUsingTemplates(NewServletClassOperation.java:245)

at org.eclipse.jst.j2ee.internal.web.operations.NewServletClassOperation.doExecute(NewServletClassOperation.java:180)

at org.eclipse.jst.j2ee.internal.web.operations.NewServletClassOperation.execute(NewServletClassOperation.java:423)

at org.eclipse.jst.j2ee.internal.web.operations.AddServletOperation.createServletClass(AddServletOperation.java:144)

at org.eclipse.jst.j2ee.internal.web.operations.AddServletOperation.doExecute(AddServletOperation.java:120)

at org.eclipse.jst.j2ee.internal.web.operations.AddServletOperation$1.run(AddServletOperation.java:426)

at org.eclipse.jst.jee.model.internal.JEE5ModelProvider.modify(JEE5ModelProvider.java:237)

at org.eclipse.jst.j2ee.internal.web.operations.AddServletOperation.execute(AddServletOperation.java:432)

at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl$1.run(DataModelPausibleOperationImpl.java:376)

at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1797)

at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(DataModelPausibleOperationImpl.java:401)

at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(DataModelPausibleOperationImpl.java:352)

at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.doExecute(DataModelPausibleOperationImpl.java:242)

at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.executeImpl(DataModelPausibleOperationImpl.java:214)

at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.cacheThreadAndContinue(DataModelPausibleOperationImpl.java:89)

at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.execute(DataModelPausibleOperationImpl.java:202)

at org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard$1$CatchThrowableRunnableWithProgress.run(DataModelWizard.java:211)

at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:369)

at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:313)

at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:934)

at org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard.runOperations(DataModelWizard.java:220)

at org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard.performFinish(DataModelWizard.java:178)

at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:742)

at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:373)

at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:618)

at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:227)

at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)

at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)

at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)

at org.eclipse.jface.window.Window.runEventLoop(Window.java:820)

at org.eclipse.jface.window.Window.open(Window.java:796)

at org.eclipse.ui.actions.NewWizardAction.run(NewWizardAction.java:182)

at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)

at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:546)

at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490)

at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:402)

at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)

at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)

at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)

at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)

at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)

at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)

at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)

at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)

at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)

at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)

at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)

at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)

at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:508)

at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)

at org.eclipse.equinox.launcher.Main.run(Main.java:1173)

我目前正在使用java 1.6.0_32,Tomcat 7.0.27和Eclipse Europa。

我该如何解决这个错误?

2 个答案:

答案 0 :(得分:1)

可能是你的Eclipse安装有问题。尝试重新安装WTP或get新的日食。

答案 1 :(得分:0)

我有类似的问题。我正在使用eclipse-Kepler-sr2-javaEE。

问题出在Tomcat-7服务器上。我从project-explorer以及Windows-&gt; preferences-&gt; server-&gt; Runtime Environment中删除了服务器。

最后我能够创建Servlet。