我使用Maven Vaadin应用程序原型创建了一个新的Java项目。我的目标是在Jetty上部署一个Vaadin servlet的可执行jar。我使用Maven程序集插件。
当我汇编并运行我的应用程序时,出现以下错误:
INFO: Requested resource [/VAADIN/widgetsets/com.sevag.MyAppWidgetset/com.sevag.MyAppWidgetset.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.
当我执行" jar tf"在我的罐子里,我注意到" com.sevag.MyAppWidgetset"文件位于/ VAADIN /,而不是/ VAADIN / widgetsets:
VAADIN/com.sevag.MyAppWidgetset/clear.cache.gif
...
VAADIN/com.sevag.MyAppWidgetset/com.sevag.MyAppWidgetset.nocache.js
...
我该如何解决这个问题?
我没有使用web.xml文件,我依赖于Vaadin servlet注释。这是Vaadin servlet代码(它是默认由Maven Vaadin原型创建的" Click me"按钮):
@Theme("mytheme")
@Widgetset("com.sevag.MyAppWidgetset")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {...}
@WebServlet(urlPatterns = { "/myapp", "/myapp/*", "/VAADIN/*", "/vaadin/*" }, name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
我的maven-assembly插件配置如下:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.sevag.myapp.MyApp</mainClass>
</manifest>
</archive>
<descriptor>src/assembly/assembly.xml</descriptor>
</configuration>
</plugin>
assembly.xml文件如下所示:
...
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/webapp</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>target/classes</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
Jetty servlet代码如下:
server = new Server(PORT);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setResourceBase("./src");
context.setCopyWebDir(true);
context.setCopyWebInf(true);
ServletHolder vaadinLoader = new ServletHolder(new MyUI.MyUIServlet());
context.addServlet(vaadinLoader, "/*");
context.addServlet(vaadinLoader, "/VAADIN/*");
context.addServlet(vaadinLoader, "/vaadin/*");
context.addServlet(vaadinLoader, "/myapp/*");
context.addServlet(vaadinLoader, "/myapp");
server.setHandler(context);
修改
我找到了一个临时(或可能是永久性的)解决方法。由于我不需要自定义widgetset,因此我遵循了以下答案:
How can I compile only necessary widgets in Vaadin 7 with Maven?
com.vaadin.DefaultWidgetSet被放在jar中的正确位置(VAADIN / widgetset / com.vaadin.DefaultWidgetSet)。