我使用Eclipse GWT插件创建了一个示例GWT Web应用程序,它可以完美运行。

但是当我尝试添加新模块时,

  • 右键单击我的Web应用程序项目
  • 选择新|其他... | GWT类|模块选项;和
  • 单击向导上的下一步按钮

  • 什么也没发生-向导继续保留在同一页面上!

    接下来,我复制粘贴了我正在使用的Web应用程序的包/目录结构,并手动对NewModule.gwt.xml及其内容进行了适当的更改;我还适当地更改了Java类名,并刷新了Eclipse项目。

    但是,现在,当我在项目上运行GWT Compile时(通过在Eclipse中右键单击该项目),它仅编译原始的webapp,而完全忽略了我在文件系统上手动创建的NewModule模块。

    问题:
  • 我在做什么错?
  • 是否有命令行方法可以简化现有Web应用程序中新模块创建的过程,或者理想情况下,将其创建为独立实体?

  • 我在Ubuntu 16.04上将GWT 2.8.0与Eclipse Neon一起使用。也尝试了GWT 2.7.0,具有与上述相同的行为。

    最佳答案

    我可以重现这一点。值得庆幸的是,记录了一个事件,它将为我们提供一些想法:

    Plug-in:   org.eclipse.ui
    Serverity: Error
    Message:   Unhandled event loop exception
    
    java.lang.ClassCastException: org.eclipse.jdt.internal.core.JarEntryFile cannot be cast to org.eclipse.core.resources.IFile
        at com.google.gwt.eclipse.core.modules.AbstractModule.getShortName(AbstractModule.java:294)
        at com.google.gwt.eclipse.core.modules.AbstractModule.getQualifiedName(AbstractModule.java:272)
        at com.google.gwt.eclipse.core.modules.ModuleJarResource.getQualifiedName(ModuleJarResource.java:1)
        at com.google.gwt.eclipse.core.modules.AbstractModule.getSimpleName(AbstractModule.java:342)
        at com.google.gwt.eclipse.core.modules.ModuleJarResource.getSimpleName(ModuleJarResource.java:1)
        at com.google.gwt.eclipse.core.modules.ModuleUtils$3.visit(ModuleUtils.java:220)
        at com.google.gwt.eclipse.core.modules.ModuleUtils$3.visit(ModuleUtils.java:1)
        at com.google.gwt.eclipse.core.modules.ModuleUtils.visitFragments(ModuleUtils.java:338)
        at com.google.gwt.eclipse.core.modules.ModuleUtils.findModule(ModuleUtils.java:212)
        at com.google.gwt.eclipse.core.wizards.NewModuleWizardPage.addCommonGWTModulesAsDefaultInherits(NewModuleWizardPage.java:367)
        at com.google.gwt.eclipse.core.wizards.NewModuleWizardPage.moduleContainerChanged(NewModuleWizardPage.java:496)
        at com.google.gwt.eclipse.core.wizards.NewModuleWizardPage.doFieldChange(NewModuleWizardPage.java:291)
        at com.google.gwt.eclipse.core.wizards.NewModuleWizardPage.handleFieldChanged(NewModuleWizardPage.java:322)
        at org.eclipse.jdt.ui.wizards.NewContainerWizardPage.containerDialogFieldChanged(NewContainerWizardPage.java:319)
        at org.eclipse.jdt.ui.wizards.NewContainerWizardPage.access$1(NewContainerWizardPage.java:314)
        at org.eclipse.jdt.ui.wizards.NewContainerWizardPage$ContainerFieldAdapter.dialogFieldChanged(NewContainerWizardPage.java:300)
        at org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField.dialogFieldChanged(DialogField.java:75)
        at org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField.setText(StringDialogField.java:180)
        at org.eclipse.jdt.ui.wizards.NewContainerWizardPage.setPackageFragmentRoot(NewContainerWizardPage.java:470)
        at org.eclipse.jdt.ui.wizards.NewContainerWizardPage.initContainerPage(NewContainerWizardPage.java:163)
        at com.google.gwt.eclipse.core.wizards.NewModuleWizardPage.initModulePage(NewModuleWizardPage.java:328)
        at com.google.gwt.eclipse.core.wizards.NewModuleWizard.addPages(NewModuleWizard.java:55)
        at org.eclipse.jface.wizard.WizardSelectionPage.getNextPage(WizardSelectionPage.java:116)
        at org.eclipse.ui.internal.dialogs.WorkbenchWizardSelectionPage.getNextPage(WorkbenchWizardSelectionPage.java:98)
        at org.eclipse.jface.wizard.WizardDialog.nextPressed(WizardDialog.java:869)
        at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:419)
        at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:618)
        at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5219)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1340)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4553)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4143)
        at org.eclipse.jface.window.Window.runEventLoop(Window.java:818)
        at org.eclipse.jface.window.Window.open(Window.java:794)
        at org.eclipse.ui.internal.handlers.WizardHandler$New.executeHandler(WizardHandler.java:269)
        at org.eclipse.ui.internal.handlers.WizardHandler.execute(WizardHandler.java:290)
        at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:295)
        at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
        at sun.reflect.GeneratedMethodAccessor75.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
        at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:282)
        at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:264)
        at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
        at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
        at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)
        at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:488)
        at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
        at org.eclipse.ui.internal.handlers.LegacyHandlerService.executeCommand(LegacyHandlerService.java:353)
        at org.eclipse.ui.internal.actions.CommandAction.runWithEvent(CommandAction.java:155)
        at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
        at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:397)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5219)
        at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1340)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4553)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4143)
        at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
        at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
        at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
        at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:687)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:604)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
        at org.eclipse.equinox.launcher.Main.main(Main.java:1492)
    

    其次是:
    Session Data:
    
    eclipse.buildId=4.6.1.M20160907-1200
    java.version=1.8.0_112
    java.vendor=Oracle Corporation
    BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
    Framework arguments:  -product org.eclipse.epp.package.jee.product --launcher.GTK_version 2
    Command-line arguments:  -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.jee.product --launcher.GTK_version 2
    
    This is a continuation of log file /home/user/workspace/.metadata/.bak_0.log
    Created Time: 2017-05-02 11:19:21.409
    

    在我的情况下,该.bak_0.log中没有什么有趣的/新的。我已将其报告给Eclipse,并且还记录了354的问题gwt-eclipse-plugin

    编辑:当然,这并不能回答您的真正问题,我也将看看是否可以帮助您。

    编辑2:

    由于您已经手动添加了模块,因此我将假定IDE集成对此一无所知。右键单击您的项目,转到GWT,然后从展开菜单中选择“设置”,而不是进行编译。您在对话框中看到新模块了吗?如果没有,请添加它,然后查看GWT Compile是否开始为您工作。

    关于命令行,请参考webAppCreator documentation

    编辑3:

    好的,现在我无法重现您的行为。我再次开始演示代码,然后复制它,以便在同一项目中有2个模块。它们不会互相继承或继承任何东西-暂存引用scratch / scratch2引用scratch2。我没有创建另一个HTML文件来引用第二个模块。所以这是我的设置:
    ./src/scratch/server/GreetingServiceImpl.java
    ./src/scratch/shared/FieldVerifier.java
    ./src/scratch/client/Scratch_gwt.java
    ./src/scratch/client/GreetingService.java
    ./src/scratch/client/GreetingServiceAsync.java
    ./src/scratch/Scratch_gwt.gwt.xml
    
    ./src/scratch2/server/GreetingService2Impl.java
    ./src/scratch2/shared/FieldVerifier2.java
    ./src/scratch2/client/GreetingService2Async.java
    ./src/scratch2/client/Scratch2_gwt.java
    ./src/scratch2/client/GreetingService2.java
    ./src/scratch2/Scratch2_gwt.gwt.xml
    

    我不知道它是否相关(有点怀疑),但我也修改了我的web.xml:
      <servlet>
        <servlet-name>greetServlet</servlet-name>
        <servlet-class>scratch.server.GreetingServiceImpl</servlet-class>
      </servlet>
      <servlet>
        <servlet-name>greetServlet2</servlet-name>
        <servlet-class>scratch2.server.GreetingService2Impl</servlet-class>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>greetServlet</servlet-name>
        <url-pattern>/scratch_gwt/greet</url-pattern>
      </servlet-mapping>
    
      <servlet-mapping>
        <servlet-name>greetServlet2</servlet-name>
        <url-pattern>/scratch_gwt/greet2</url-pattern>
      </servlet-mapping>
    

    当我右键单击我的scratch-gwt项目并转到GWT |编译,我有:
    Project: scratch-gwt
    Log level: Info
    Ouput style: Obfuscated
    Entry Point Modules
        Scratch_gwt - scratch
        Scratch2_gwt - scratch2
    

    我确实必须在此处添加Scratch2_gwt入口点。和我的编译输出:
    Compiling module scratch.Scratch_gwt
       Compiling 5 permutations
          Compiling permutation 0...
          Compiling permutation 1...
          Compiling permutation 2...
          Compiling permutation 3...
          Compiling permutation 4...
       Compile of permutations succeeded
       Compilation succeeded -- 11.274s
    Linking into /home/user/workspace/scratch-gwt/war/scratch_gwt
       Link succeeded
       Linking succeeded -- 0.180s
    Compiling module scratch2.Scratch2_gwt
       Compiling 5 permutations
          Compiling permutation 0...
          Compiling permutation 1...
          Compiling permutation 2...
          Compiling permutation 3...
          Compiling permutation 4...
       Compile of permutations succeeded
       Compilation succeeded -- 7.821s
    Linking into /home/user/workspace/scratch-gwt/war/scratch2_gwt
       Link succeeded
       Linking succeeded -- 0.109s
    

    因此,我只能说确实可以做到这一点。重新整理您的编译设置,然后从头开始一个新项目以重试,或者发布一些配置。

    10-07 13:24
    查看更多