Creating a new project from scratch

Usually, you would use the vaadin-archetype-application or vaadin-archetype-application-multimodule Maven archetypes to create a new Vaadin application. There's nothing wrong with using these if the generated code suits your needs. However, these archetypes generate more code than you need, partially because they try to show you how to get started with Vaadin and partially because they are general-purpose starters which are well-suited for most projects. But let's gain full control (and understanding) of the web application by creating a Vaadin project in a very different way—a more fine-grained, controlled way.

A Vaadin application is, at the end of the day, a Java application packaged as a WAR file. You can think of it as a standard web application in which you drop some JARs that allow you to build a web UI using the Java Programming Language instead of HTML and JavaScript. Is it as simple as dropping some JARs into your Java project? Let's find out!

Use the maven-archetype-webapp to generate a simple Java web application by executing the following on the command line:

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp

Use the following properties when prompted:

  • groupId: packt.vaadin.datacentric.chapter01
  • artifactId: chapter-01
  • version: 1.0-SNAPSHOT
  • package: packt.vaadin.datacentric.chapter01
IDEs such as NetBeans, Eclipse, and IntelliJ IDEA have excellent support for Maven. You should be able to create a new Maven project using the previous archetype in your IDE by providing the corresponding Maven coordinates without using the command line.

Clean up the pom.xml file to make it look like the following:

<project ...>
<modelVersion>4.0.0</modelVersion>

<artifactId>chapter-01</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
</project>
Note that in the code provided with this book, you’ll find a <parent> section in the pom.xml file of the chapter-01 project. This is because all the demo applications of the book have been aggregated into a single Data-centric-Applications-with-Vaadin-8 Maven project for your convenience. You don’t need to add any <parent> section to your project if you are following the steps in this chapter.

Remove the src/main/webapp and src/main/resources directories. This deletes the generated web.xml file which will make Maven complain. To tell it that this was intended, add the following property to your pom.xml file:

    ...
<packaging>war</packaging>

<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
...

Also, add the following properties to configure Maven to use Java 8:

        <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset