Running an Application

Running a Spring Boot Project

If you are developing a Spring Boot project, Spring Boot makes it easier to run a Java web application, because it takes care of starting and configuring the server.

To run your application, all you need to do is to run the Application class that contains the main method that starts Spring Boot. IntelliJ automatically detects that you have a class with a main() method and displays it in the run configurations dropdown.

To start the application, either:

  • Click the play button next to the run configurations dropdown.

  • Open Application.java and click the play button next to the code line containing the main method.

The first time you start a Vaadin application, it downloads frontend dependencies and builds a JavaScript bundle. This can take several minutes, depending on your computer and internet speed.

You will know that your application has started when you see the following output in the console:

Tomcat started on port(s): 8080 (http) with context path ''
Started Application in 80.189 seconds (JVM running for 83.42)

You should now be able to open the web application at localhost:8080.

Running Maven Goals

You can use Maven to compile and run a Vaadin application. IntelliJ IDEA has an excellent integration with Maven. You can run common commands such as mvn install without having to leave the IDE.

You can run the application in a development server with Maven goals such as jetty:run (plain Java), tomee:run (Java EE and CDI), or spring-boot:run (Spring Boot). Notice that with Spring Boot, you can simply run the application class, as described in Running a Spring Boot Project.

  1. Open the Maven view by clicking the vertical tab on the right side of the IntelliJ IDEA window:

    Maven projects view

    This view shows all the available Maven projects and their build phases and build goals.

  2. Let us say you want to run mvn install. To do that, expand the project tree in the Maven view to show the corresponding lifecycle phase.

  3. Double-click install.

You will see how IntelliJ idea executes the install build phase. First, it executes all the previous phases in the Maven’s default lifecycle. Finally at the install phase, it downloads dependencies and copies the generated artifacts into your local Maven repository, among other things.

You can use a similar approach to run any Maven goal. For example, you can double-click the jetty:run goal in the Plugins sub-tree to deploy and run the web application implemented in the project you imported. Similarly, if you are using Spring Boot, you can double-click spring-boot:run to run the application.

To learn more about the topics covered here:

Creating a Running Configuration

Since using a goal to run the application could be a frequent task during the development, you may want to create a running configuration for it.

A running configuration is a shortcut to run a specific task from within the IDE. In the following, we create a running configuration for the jetty:run Maven goal to make it simpler to run the web application.

  1. Open the Maven view.

  2. Right-click the jetty:run, tomee:run, or spring-boot:run item under the appropriate folder.

    Technology StackEmbedded ServerGoal to Run

    Spring Boot

    spring-boot:run

    CDI / Java EE

    Apache TomEE

    tomee:run

    Plain Java

    Jetty

    jetty:run

  3. Select Create 'webapp [jetty:run]' (or tomee:run or spring-boot:run):

  4. For simplicity, change the name of the configuration to Run on Jetty (or TomEE or Spring Boot)

  5. Click OK:

You should see the new option on the top right corner of IntelliJ IDEA:

Now you can deploy and run the web application by clicking the run (or the debug) icon in the toolbar:

Redeploying During Development

If you edit and save any of the source files, they will be compiled automatically, but you can only see the changes by restarting the server. In the Run panel, click the Rerun icon, or press Ctrl+5 in the editor. You can then refresh the page to use the updated version.

You can also enable Live Reload to have the page refreshed automatically.