Friday, 18 May 2012

How to create a Vaadin project in Eclipse that uses Maven

Vaadin is a web application development framework that is increasingly getting popular with Java developers. The most alluring aspects of using this framework include,
  1. Not having to write Javascript code
  2. Not having to bother with browser compatibility
  3. Ease of creating beautiful websites with minimal code
  4. Ability to use themes to change the look and feel of the website
So, in this article I will be creating a basic Vaadin project using Maven, on Eclipse. The only pre-requisite for this is, you should have an Apache Tomcat server configured on Eclipse. If you don't, all the steps I had mentioned in my article about the Glassfish server are applicable for Tomcat too (except of course, you search for Tomcat instead of Glassfish.) Let me get started now,

Step 1:  Create a Maven Project
You can do this by clicking on File -> New -> Other and choosing Maven project as shown below.
Create Maven Project
Step 2:  Add the Vaadin archetype
Click on Next to reach the screen that lists your available archetypes. Then click on the Add Archetype button.
Add Vaadin Archetype
Step 3:  Add the Vaadin archetype details
Type in the following details,
Archetype Group ID: com.vaadin
Archetype Artifact ID: vaadin-archetype-sample
Archetype Version: LATEST

Click OK and after a short while you will be able to find the Vaadin archetype in the list of available archetypes.
Step 4:  Put in your project details
What you put in here, is up to you. Click Finish once you have filled it in.
New Vaadin Project
Your new project will now be created, configured with Vaadin, ready to run.

Step 4:  Run the project on Tomcat server
In the Project Explorer, right-click on your newly created project, and choose Run As -> Maven Build.
In the next screen that shows up, type in tomcat:run in the Goals field, and click Run. Your project will now run on an embedded Tomcat server instance.
Run configuration
Step 5:  View your web application on a browser Well, if everything went correctly, you will now be able to visit your project in your browser.
There, your Vaadin project is ready and fully configured on Eclipse. Just go ahead and add in your source code in the src/main/java/. Do remember to click the stop button in your console window before running the project again.

Thanks for reading. Please do let me know if you find any faults with my articles. I always look forward to your reviews and comments.

1 comment: