本文介绍了无法在 Eclipse 中的 Maven 项目中加载 Widgetsets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 eclipse 中使用 maven 创建了一个 vaadin Web 应用程序.特别是我使用了 vaadin-archetype-touchkit 原型,如 vaadin 书(20.3.4).在没有对默认生成的代码做任何更改的情况下,我使用 maven 运行它,目标是 clean package.然后我编译了Widgetset.当我尝试在 Tomcat 7 上运行它时,我收到来自网页的奇怪消息:

I have created a vaadin web application using maven in eclipse. In particular I have used the archetype vaadin-archetype-touchkit as described in the book of vaadin (20.3.4). Without making any change on the default generated code I have run it with maven with goals clean package. Then I compiled the Widgetset. When I try to run it on Tomcat 7, I receive the strange message from the webpage:

Failed to load the WidgetSet:
<WidgetSet Path>.DefaultWidgetSet.nocache.js

在控制台上,我也看到了错误消息:

On the console I see also the error messages:

INFO: Requested resource [/VAADIN/themes/reindeer/styles.css] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.

INFO: Requested resource [/VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/com.vaadin.DefaultWidgetSet.nocache.js] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.

INFO: Requested resource [/VAADIN/themes/reindeer/styles.css] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder.

令我震惊的是 maven 没有创建 web.xml 文件,尽管我在教程中读到 vaadin 7 不再需要它.我已阅读​​类似问题,其中建议应该在 web.xml 文件中进行调整.我是否应该推断我还必须手动创建一个 web.xml 文件?

It has struck me maven has not created a web.xml file, although I have read in the tutorial that it is no more necessary in vaadin 7. I have read the similar question where it is proposed that an adjustment in web.xml file should be done. Should I infer that I have also to create a web.xml file manually?

我也觉得很奇怪,当我对典型的 vaadin 7 应用程序的原型尝试相同的过程时,它运行正常.由于我必须开发一个 touchkit 应用程序,我将不胜感激任何关于我最初尝试中可能遗漏的建议.

I find strange as well, that when I tried the same procedure with the archetype for a typical vaadin 7 application, it runs properly. Since I have to develop a touchkit-application I would appreciate any suggestion-idea abut what could be missing on my original attempt.

推荐答案

如果您使用 servlet 3.0 配置,则不再需要 web.xml (按照 4.8.3. WEB Servlet 类)

The web.xml is no longer needed only if you use servlet 3.0 configuration (annotating your servlet as described 4.8.3. WEB Servlet Class)

通常您会以这种方式配置您的 Vaadin 3.0 Servlet 配置:

Usually you'd configure your Vaadin 3.0 Servlet Config in this way:

public class MyUI extends UI {

      @WebServlet(value = "/*", asyncSupported = true)
      @VaadinServletConfiguration(productionMode = false, ui = MyUI.class)
      public static class Servlet extends VaadinServlet {
      }

      @Override
      protected void init(VaadinRequest request) {
            //your init stuff here
      }
}

使用 @VaadinServletConfiguration 作为设置 vaadin 相关参数的快捷方式.

Where using the @VaadinServletConfiguration as shortcut for setting vaadin-related params.

现在,如果您的项目中没有 vaadin 插件(所以您使用的是默认小部件集),就是这样,不需要更多工作.

Now, if you have no vaadin addon in your project (so you're using the default widgetset), that's it, no more work is required.

相反,如果您使用自定义插件,则必须通过以这种方式添加 widgetset 参数来指定要在 @VaadinServletConfiguration 中使用的小部件集

Instead, if you're using custom addons, you must specify which widgetset to use in the @VaadinServletConfiguration simply by adding the widgetset parameter in this way

public class MyUI extends UI {

      @WebServlet(value = "/*", asyncSupported = true)
      @VaadinServletConfiguration(widgetset="com.bla.bla.MyWidgetSet",productionMode = false, ui = MyUI.class)
      public static class Servlet extends VaadinServlet {
      }

      @Override
      protected void init(VaadinRequest request) {
            //your init stuff here
      }
}

否则你必须像往常一样手动创建 web.xml...

Otherwise you must create the web.xml manually as usual...

说到 maven,我认为您只需运行 mvn clean package 并且在打包阶段 maven-vaadin-plugin 将自动编译您是小部件集.

When it comes to maven, I think you've just to run mvn clean package and on the package phase the maven-vaadin-plugin will compile you're widgetset automatically.

这篇关于无法在 Eclipse 中的 Maven 项目中加载 Widgetsets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 05:32