Creating a Project with IntelliJ IDEA

The Ultimate Edition of IntelliJ IDEA includes support for creating Vaadin applications and running or debugging them in an integrated application server.

With the Community Edition, you can create a Vaadin application most easily with a Maven archetype and deploy it to a server with a Maven run/debug configuration.

For more information, see the article “ Creating a simple Web application and deploying it to Tomcat“ in the IntelliJ IDEA Encyclopedia wiki.

Creating a Vaadin Web Application Project

In the welcome page, do the following:

  1. Download and extract the Vaadin installation package to a local folder, as instructed in “Vaadin Installation Package”.

  2. Select New Project

  3. In the New Project window, select Java

  4. Enter a Project name and Project location, and select the Java SDK to be used for the project. Vaadin requires at least Java 6. If you have not configured a Java SDK previously, you can configure it here.

    idea newproject 1

    Click Next.

  5. Select Web Application Vaadin to add Vaadin technology to the project.

  6. Select Vaadin Version and Distribution installation path. You probably also want an application stub, so select Create sample application and give a name for the generated UI class.

    idea newproject 2

    Do not click Finish yet.

  7. Select Application Server in the same window. Set it as an integrated server that you have configured in IntelliJ IDEA, as described previously in “Configuring an Application Server”.

    idea newproject 3

  8. Click Finish.

The project is created with the UI class stub and a web.xml deployment descriptor.

idea newproject 4

The wizard does not currently create a servlet class automatically, and uses Servlet 2.4 compatible deployment with a web.xml deployment descriptor.

Deploying the Project

To deploy the application to the integrated web server, right-click the index.jsp file in the project and select Run ‘index.jsp’. This starts the integrated server, if it was not already running, and launches the default browser with the application page.

Creating a Maven Project

You can choose to create a Maven project in IntelliJ IDEA. This is the recommended way when using the Community Edition. You will not have the application server integration, but can deploy the application to an application server using a run/debug configuration.

  1. Select New Project

  2. In the New Project window, select Maven

  3. Enter a project name, location, and the Java SDK to be used for the project. Vaadin requires at least Java 6.

    idea maven newproject 1

    Click Next.

  4. Give a Maven GroupID, ArtifactID, and a Version for the project, or use the defaults.

    idea maven newproject 2

  5. Check Create from archetype

  6. If the Vaadin archetype is not in the list, click Add archetype, enter GroupId com.vaadin, ArtifactIdvaadin-archetype-application, and VersionLATEST (or a specific version number).

    idea maven newproject 3

    Click OK in the dialog.

  7. Select the com.vaadin:vaadin-archetype-application.

    idea maven newproject 4

    Click Next.

  8. Review the general Maven settings and settings for the new project. You may need to override the settings, especially if you are creating a Maven project for the first time.

    idea maven newproject 5

    Click Finish.

Creating the Maven project takes some time as Maven fetches the dependencies. Once done, the project is created and the Maven POM is opened in the editor.

Compiling the Project

To compile a Vaadin application using Maven, you can define a run/debug configuration to execute a goal such as package to build the deployable WAR package. It will also compile the widget set and theme, if necessary. See “Compiling and Running the Application” for more details.

Compilation is included in the following instructions for deploying the application.

Deploying to a Server

There exists Maven plugins for deploying to various application servers. For example, to deploy to Apache Tomcat, you can to configure the tomcat-maven-plugin and then execute the tomcat:deploy goal. See the documentation of the plugin that you use for more details. If no Maven plugin exists for a particular server, you can always use some lower-level method to deploy the application, such as running an Ant task.

In the following, we create a run/debug configuration to build, deploy, and launch a Vaadin Maven application on the light-weight Jetty web server.

  1. Select Run Edit Configurations.

  2. Click + and select Maven to create a new Maven run/debug configuration.

  3. Enter a Name for the run configuration. For the Command line, enter “`package jetty:run`# to first compile and package the project, and then launch Jetty to run it.

    idea maven run 1

    Click OK.

  4. Select the run configuration in the toolbar and click the Run button beside it.

    idea maven run 2

Compiling the project takes some time on the first time, as it compiles the widget set and theme. Once the run console pane informs that Jetty Server has been started, you can open the browser at the default URL http://localhost:8080/.