Overview

Skill Level: Beginner

You should have a basic understanding of the Java language, and how to build and run Java applications.

This recipe shows you how to use Eclipse to build and run rich, responsive Graphical User Interface (GUI) applications using the Vaadin framework. You will also see how to build, deploy, and run them using WLP.

Ingredients

  • Java language knowledge
  • How to build Java applications
    • See the Intro to Java Programming Learning Path, Unit 15.
  • Java Development Kit (JDK) version 8.
    • See how to install it in Step 1 below.
  • Eclipse IDE
    • See how to install it in Step 1 below.
  • Vaadin 8
    • See how install the Vaadin 4.0 plugin for Eclipse in Step 2 below.
  • WebSphere Application Server Liberty Profile (WLP)
    • See how to install WLP in Step 3 below.

Step-by-step

  1. Setup your development environment

    You will need the JDK and Eclipse IDE installed to complete this recipe. I’ll assume you have some basic Java knowledge. If not, please check out the Intro to Java Programming learning path here at IBM developerWorks.

    You will also need a working development environment. If you already have a Java development environment, skip to Step 2.

    Otherwise, check out the Introduction to Java Programming learning path, Unit 2 for step-by-step instructions. There are videos in this section as well that can assist you if you need more help.

    First, download and install the Java Development Kit (JDK), version 8, and install it on your machine. Please refer to the video below if you need help.

    Next, install the Eclipse IDE to your computer. Please refer to the video below if you need help.

    Once you have your development environment setup and ready to go, you can proceed to Step 2, where I’ll show you how to install the Vaadin 4.0 plugin for Eclipse.

  2. Install the Vaadin 4.0 plugin for Eclipse

    The Vaadin 4.0 plugin for Eclipse makes it so much simpler to develop Vaadin applications in Eclipse, so I recommend you install it. Please refer to the video below, where I show you how to install the plugin, and verify that it is working properly in your Eclipse IDE.

  3. Download and install WLP

    The WebSphere Liberty Profile is a robust application server that is easy to install, boots up quickly, and is JEE compliant.

    Please refer to the video below, where I’ll show you how to install WLP and verify that it is working on your computer.

  4. About Vaadin

    There are lots of great Vaadin resources, and I’ll list some at the end of this recipe, but I think it’s worthwhile to give you a high level overview of the Vaadin architecture.

    The figure below shows the high-level Vaadin architecture (image credit to Vaadin docs):

    Vaadin-High-level-Architecutre-1

    The user interacts with your Vaadin application through Javascript running in the browser. Because Vaadin uses Google Web Toolkit (GWT), a large number of browsers are supported right out of the box. This code is generated for you automatically, leaving you to concentrate on your application’s business logic.

    The server side entry point for your Vaadin application is a Java servlet that communicates with backend services like databases and other business logic. Your application’s main UI class is an extension of the Vaadin framework class called, well, UI. The UI class is the view (called a view port using Vaadin terminoogy) for your application, and your application must provide at least one subclass of UI. A simple use of UI looks like this:

    @Theme("mytheme")
    public class MyApp extends UI {
    protected void init(VaadinRequest request) {
    ... initialization code goes here ...
    }
    }

    The look of your application is controlled through the use of themes, which build from a Base Theme as shown in the high-level architecture diagram. A Vaadin application separates the functionality of the application (think: business logic) from the way it appears to the user using Themes. You can learn more about Vaadin themes here.

  5. Create the project

    First, let’s create the project in Eclipse. Make sure Eclipse is open, and go to File > New Project..., expand the Vaadin tab, select Vaadin 8 Project, then click Next. The next screen looks like below:

    Vaadin8ProjectWizard-1

    Select the “CRUD Example” as shown above, then click Next. On the next screen just accept the defaults and click Finish to create the project.

    The Vaadin 8 new project wizard creates several projects within your Eclipse workspace:

    Vaadin8ProjectsInEclipse

    We will only concern ourselves with three of those for the sake of this recipe:

    • myapplication – the parent project, which we will use to build the entire project
    • myapplication-backend – the backend project, which is where you write business logic and other backend services, and corresponds to the BACKEND SERVICE tire from the architecture diagram from Step 4.
    • myapplication-ui – the GUI project, which is where the User Interface code resides, and corresponds to the USER INTERFACE tier from the architecture diagram from Step 4.

    Note: If you want to learn more about the structure of the generated project, expand the myapplication parent project and open the README.md Markdown file. It explains the structure of the project, and how to build it in more detail. It also explains what the other projects are for.

    Right-click on the myapplication project in Project Explorer and choose Run As > Maven Project, and when the Run Configurations dialog opens (it will only do this the first time), select the clean and install goals.

    When the build finishes, you are ready to smoke test the generated application code, just to make sure it’s working. I’ll show you how to do that next.

  6. Smoke test the generated application code

    Before we go any further it’s probably a good idea to build and run the generated application code and make sure it works (what I’m calling the “smoke test”).

    Run using Jetty, smoke test in the browser.

    For this simple smoke test, you’ll use an embedded Jetty application server running within Eclipse. To start the server, right-click on the myapplication-ui project in Project Explorer and choose Run As > Maven Build, and enter clean jetty:run as the goals.

    When the build finishes, you should see output like this:

    [INFO] Started ServerConnector@11d422fd{HTTP/1.1}{0.0.0.0:8080}
    [INFO] Started @7544ms
    [INFO] Started Jetty Server
    [INFO] Starting scanner at interval of 2 seconds.

     Now open a browser and go to http://localhost:8080. You will see a login screen like this one:

    Login-Screen-1

    Just click the Login button (no password required), and you will be taken to the Product Inventory screen (the generated application is a sample product inventory system):

    MyCrudApplicationMainPage

     

    Congratulations! The app is up and running. In the next section, I’ll show you how to run the application under WLP, make changes to the application, and watch WLP auto-deploy your changes so you can test them.

     

    Make sure and stop the Jetty server. To do so, click on the Stop icon in the Console window:

     

    StopJettyServerInEclipse-1

  7. Develop and debug the application

    I have created a video to show you how to do the following:

    • Build the project
    • Setup a new WLP server in the Servers View.
    • Deploy to the newly created WLP server.
    • Make a simple change and watch WLP auto-deploy those changes.

    I will also show you in the video how to debug in Eclipse, and track down the bug in the code, just like you would do on a real project.

  8. What's Next?

    Learn more about Vaadin. 

    Learn more about WLP.

Join The Discussion