官术网_书友最值得收藏!

Creating a project in Eclipse IDE

In this recipe, we are going to create a new Vaadin project in the Eclipse IDE.

Getting ready

Download and install the latest version from the Eclipse download page (specifically Eclipse IDE for Java EE Developers), http://www.eclipse.org/downloads.

There is an Eclipse extension for Vaadin, which helps us with the creation of Vaadin projects, widget set compilation, and so on. The instructions on how to install the extension are at http://vaadin.com/eclipse.

How to do it...

Carry out the following steps in order to create a new project in Eclipse IDE:

  1. Open the New Project window and search for vaadin.
    How to do it...
  2. There should be a few Vaadin wizards listed. Choose Vaadin 7 Project and click on the Next button.
    How to do it...
  3. Fill in the name of the project. Select Apache Tomcat v7.0 as Target runtime and click on the Finish button.
    How to do it...
  4. Eclipse makes a Hello world application for us. All the application code has been placed in the HellovaadinUI class. Now we can run the project. Right-click on the name of the project, go to Run As, and then click on Run on Server. Choose Apache Tomcat v7.0 to run our application and confirm the dialog window.
    How to do it...
  5. The application appears in the Eclipse's Internal Web Browser or we can open the started application in our favorite browser: http://localhost:8080/HelloVaadin.
    How to do it...

How it works...

Let's have a look at what has been generated by Eclipse.

How it works...

The following table explains the content of the important directories:

Note

web.xml must contain the definition of the UI class, servlet, and URL mapping. It must be located inside the WEB-INF folder.

There's more...

Now we can try to change the code inside the HellovaadinUI class, so the application prints out the name of the system user.

String user = System.getProperty("user.name");
Label label = new Label("Hello Vaadin user: " + user);
layout.addComponent(label);

Tip

Notice we can see the changes in code without restarting the application server. The project is recompiled after we save a file and changes are visible in the browser right away.

We need to add the ?restartApplication parameter into the URL when running a Vaadin application with the @PreserveOnRefresh annotation on our UI class.

主站蜘蛛池模板: 兴城市| 呼伦贝尔市| 凯里市| 彭阳县| 内黄县| 繁昌县| 陕西省| 永嘉县| 肇庆市| 繁昌县| 民权县| 齐齐哈尔市| 抚州市| 上杭县| 洞口县| 建德市| 河北省| 依安县| 甘南县| 隆德县| 绥德县| 黎平县| 墨玉县| 射洪县| 张家口市| 五大连池市| 开化县| 礼泉县| 青阳县| 合作市| 崇礼县| 晋江市| 无为县| 通州市| 皋兰县| 于都县| 清水河县| 禹州市| 梧州市| 龙南县| 罗甸县|