I created a new Java project with the Maven Vaadin application archetype. My goal was to have an executable jar that deployed a Vaadin servlet on Jetty. I use the Maven assembly plugin.
When I assemble and run my application, I get the following error:
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.
When I execute "jar tf" on my jar, I noticed that the "com.sevag.MyAppWidgetset" files are located in /VAADIN/, not /VAADIN/widgetsets:
VAADIN/com.sevag.MyAppWidgetset/clear.cache.gif
...
VAADIN/com.sevag.MyAppWidgetset/com.sevag.MyAppWidgetset.nocache.js
...
How do I fix this?
I don't use a web.xml file, I rely on the Vaadin servlet annotations. This is the Vaadin servlet code (it's the default created by the Maven Vaadin archetype with the "Click me" button):
@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 {
}
}
My maven-assembly plugin is configured as follows:
<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>
The assembly.xml file looks like this:
...
<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>
The Jetty servlet code is as follows:
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);
Edit
I found a temporary (or possibly permanent) workaround. Since I don't need a custom widgetset, I followed this answer:
How can I compile only necessary widgets in Vaadin 7 with Maven?
The com.vaadin.DefaultWidgetSet is being put in the correct place in the jar (VAADIN/widgetset/com.vaadin.DefaultWidgetSet).