Friday, November 7, 2008

Hello World with Eclipse RCP - Your First Application

As discussed in the article Using Eclipse for RCP Application Development, Eclipse is free and open-source software that people use to develop Java-based programs called Rich Client Platform (RCP) applications. Using a computer with any operating system (I happen to be using Mac OSX), you can use Eclipse to create an advanced program that can be deployed on Mac, Linux, and/or Windows OS. In this article, I will show how easy it is to get started using Eclipse and make your very own application even if you never wrote a line of code in your life. The program is going to be the classic "Hello World" application that programmers often write as their first program when trying out a new coding language or Integrated Development Environment (IDE). Before following along you'll need to have Eclipse and the Java Runtime Environment (JRE) installed as described here.

Step 1: Launch Eclipse and choose a "workspace". The workspace is where all the files needed for the application, either generated by Eclipse or written by you, will be located. The location I chose for my workspace is in a folder called "workspace" located in the directory that my Eclipse IDE folder resides. Once your application is created, you can navigate to that folder on your hard drive and actually find the files there.
Step 2: Launch the new project wizard in Eclipse. Select "File" from the menu, choose "New" and click "Project".

Step 3: When the new project wizard launches, select "Plugin Project" and click "Next".

Step 4: Enter a Project name and click "Next". The nomenclature that Java developers use is [top-level domain.your personal or company's domain name.project or application name]. So for me I entered com.timmolter.helloWorld. The reason for this is to avoid projects with the same name existing elsewhere in the world. If you named your project HelloWorld, there is a chance that there will be other projects out there named the exact same thing, which is bad. Sometimes people share their projects with the world, and having a unique project naming system keeps things in order. The point is to have a unique name that no one else will use.

Step 5: Choose "Yes" for "Would you like to create a rich client application?" and click "Next".

Step 6: Select the "Hello RCP" template and click "Finish".

Step 7: You may be asked if you want to use the Plug-in Development perspective. Choose Yes. This just specifies how you want the Eclipse IDE to be laid out when working on RCP applications.

Step 8: The new project wizard has created a project for you with all the necessary files and settings to make it an RCP Application. On the left side of the IDE you will see a view called "Package Explorer" which contains your new Hello World application files. These files shown in the view match what is found in your workspace folder, which you set up earlier. Navigate to your workspace folder and you should see your new project there.

Step 9: Launch your Hello World application. To do this, you need to be looking at the "Overview" shown in the center view above. This should have been the default thing displayed, but if it is not, just double-click on "MANIFEST.MF" in the "META-INF" folder in your new project folder in the Package Explorer view. On the "Overview" tab, click on the link called "Launch an Eclipse Application" in the "Testing" area. A small window should pop up with "Hello RCP" written at the top. Congrats, you just created and ran your first Eclipse RCP application!

After you close the program, feel free to look around the Overview of your project and also the "src" folder that is part of your project. The "src" folder is where the code that defines your program resides. There should be a package named the same as your project containing a handful of .java files. If you double-click on any of the .java files, they will open up in an editor view in the center of the Eclipse IDE. You may find it satisfying to open up and change the title of your application in the preWindowOpen() method, by changing the "Hello RCP" string to something different and re-running the application.

While the Hello World program is quiet boring, it is nonetheless the first step in creating a real application that actually does something useful.

Next ---> Adding a View to an Eclipse RCP Application
<--- Previous - Using Eclipse for RCP Application Development

Also see: Eclipse RCP Tutorial Table of Contents

No comments: