Search code examples
maven-2vaadin7intellij-14

How to run the most basic of Vaadin applications


I've been attempting to create an out-of-the-box Vaadin application and have thus far been unsuccessful.

Using IntelliJ IDEA 14, added the correct Vaadin maven archetype and have created the application.
I end up with three project folders (production, ui and widgetset) where, according to the tutorials, I would have expected only a few files under src. Anyway.

So now when I try to deploy under Tomcat I get the infamous

Requested resource [/VAADIN/widgetsets/com.vaadin.DefaultWidgetSet/com.vaadin.DefaultWidgetSet.nocache.js] not found from filesystem or through class loader.

error. Enough articles on how to change the web.xml file to solve that. However, I have no web.xml file to alter.

I also don't need to add any client js so I don't really need any of that stuff, I just need server-side Vaadin.

Can I get rid of the whole WidgetSet dependency, thereby also getting rid of this error and just run the most basic of server-side Vaadin applications without all the fancy things?

I've tried commenting out all references to client compiler, widgetset and everything else my puny knowledge of Java allows me to and have lost days in the process.

Some genius insight would be awesome. Thanks in advance.


Solution

  • So I get you have a rough idea on how Vaadin works. Here's a bit of background info just to clear some things up and maybe give the relevant info to others interested as well.

    GWT idea is that you do an app in Java and run it through the GWT compiler. Out comes javascript that you can run in the browser directly. The compiler itself is most of what GWT is. The options for readymade functionality in terms of widgets or components is quite slim. It is more of a 'do it yourself' mentality where they let the GWT users or other framework makers fill the widget/graphical gap.

    Vaadin uses GWT but in a bit different way than most frameworks built on GWT. Just as other GWT extending frameworks, Vaadin includes a set of widgets that gives you the the possibility to build most parts of your apps without the need to modify the widgets. The thing Vaadin does differently is that it precompiles the widgets and on top of it and gives you a communication manager that allows you to steer the widgets from a server. This key difference is here that when in almost all other GWT frameworks you have to run the GWT compiler after every single UI change you do, in Vaadin you don't have to because the server steers the layouting and widgets with JSON messages. In Vaadin you compile when you change the behavior of a widget, and not when you use it.

    Because Vaadin doesn't require you to 'GWT compile' the application all the time, it can provide you with a precompiled widgetset for your basic needs. This is called DefaultWidgetSet. It is enough as far as you don't do client side changes or use any add-ons found in the root directory.

    And then to the actual problem. The archetype that you are using came out a week ago. I don't know which tutorial you are referring to but my bet is that it is still referring to the old archetype and it should be updated. Normally you should be able to get it to run the app with these steps:

    1. create the project with archetype
    2. run mvn install in the root folder
    3. run mvn jetty:run in the ui folder (or alternatively deploy ui into another servlet container, like tomcat, through your IDE)

    Because you get the error message that you posted, it indicates that the application is in fact trying to use the precompiled version, which is fine, but for some reason it can't find it. It should come from the widgetset module, from the vaadin-client-compiled dependency in it:

    <dependency>
      <groupId>com.vaadin</groupId>
      <artifactId>vaadin-client-compiled</artifactId>
      <version>${vaadin.version}</version>  
    </dependency>
    

    ${vaadin.version} can be defined globally (as you should have there) or then you can type in the version number in there directly, like 7.3.7. For some reason it doesn't seem to find this. If it is not there, add it to the widgetset pom.xml, and run mvn install in widgetset (or parent, both are fine). Then go to ui and start up the server again with mvn jetty:run.

    I'm not sure but my guess here is that the archetype has a custom widgetset and doesn't depend on the precompiled widgetset. After that you've wanted the default widgetset instead of a custom one and removed the annotation for the widgetset in the UI class, but you have not added the dependency for the default widgeset.

    As your use-case is very simple, the archetype in question might be a bit overkill. You have no reason to have the project split up in ui and widgetset if you don't develop client side and a module for building a production-ready deployment package (production module) is certainly out of scope at this point. So in that sense widgetset, production and parent -modules are completely irrelevant for you.

    If you want a simpler project structure you could clone my git repo found here: https://github.com/Peppe-/hello-world. It has the old Vaadin default single-module archetype as a base but I ripped out everything that is not needed to develop purely server side with no fuss. pom.xml went down from about 200 rows of declarations to 80, but it also means that you have to add stuff back if you want additional features into use. Like the compiler, or if you want to adds css (modify theme). You can get it and run it with these command:

    git clone https://github.com/Peppe-/hello-world.git
    cd hello-world
    mvn jetty:run
    

    Or after the first step you can import it into IDEA and run it from there. Additionally rename the package (by renaming the folders within src) if you want to use your own package name.

    Sorry I got a bit carried away and rambled on. Please ask any and all questions if I missed something.