administration mode
Pssst...Ferdy is the creator of JungleDragon, an awesome wildlife community. Visit JungleDragon

 

Article: Eclipse for the versatile developer »

FERDY CHRISTANT - JUL 7, 2006 (11:16:33 AM)

 

This articles explains how to use Eclipse to setup a workspace that allows for C/C++, Java/J2EE and PHP development. Included are installation instructions and tutorials on how to set up and run a simple project for all 4 development environments.

This article will later be updated to include additional instructions for basic Eclipse plugins, such as version control.

Introduction

By now you are probably aware of the existence of Eclipse, the open source project that delivers a cross platform rich client framework. Eclipse is used as a base for many modern desktop applications, thanks to the plugin architecture. In the community it is mostly used as an IDE for software development, particularly for Java. In the past it has been challenging to setup Eclipse as a multi-language development environment, due to complex version dependencies between the Eclipse base and the plugins on top of it. With the release of Eclipse Callisto, a streamlined package of the Eclipse base and 10 important plugins, this is a thing of the past. Follow along how we use Eclipse Callisto to set up a working environment for C/C++, Java/J2EE, and PHP development.

Base Installation

There are multiple ways to install Callisto. Let's go for the option where we can customize what to install. Head over to the custom download site. We will first install the Eclipse base and then use the discovery site to update our base, so go ahead and download the "Eclipse Platform Runtime Binaries" for your platform. When completed, extract the archive to a location of your choice and run the eclipse.exe file (on Windows).

When Eclipse is started, it will prompt you for the workspace location. You can either choose one on each startup or choose a permanent one for all your projects. After this choice, go to "Help->software updates->Find and install...". Choose "Search for new features to install". Click "Next" and then tick the "Callisto Discovery Site". Click on "Finish". When prompted for a mirror, choose one that is nearest to you. The next step is important, we will select what to install on top of Eclipse. Because we want to be versatile, select all options, but if you want you can exclude some, such as the data tools and modelling features.

Whenever the system complains about feature dependencies, click the "Select required" button, marked in red in the screenshot above. Click "Next" and "Finish", and get yourself some coffee, the download and installation will take a while. Note: if you are looking for the PHP option, stop looking. PHP is not part of Eclipse or Callisto, we will install it as a separate plugin later.

Restart Eclipse as soon as the installation finishes. We are now ready to evaluate our installation by creating some simple projects for each language.

HelloWorld in C

Although we have selected to install the plugins for C and C++ development, Eclipse still depends on an external compiler for this type of development. GCC is the prefered choice for this. This means that we have to install GCC on our client machine and make it available on the system path. Most Linux distribution are configured like this by default. For Windows, I have used Cygwin:

  • Run the Cygwin setup program.
  • At a minimum, select the GCC options in the development category of the installation options. I have chosen to install all development tools, but be aware of the overhead.
  • Once installation is completed, add the Cygwin installation directory to your system path (Start->Settings->Control panel->System->Advanced->Environment variables->Path)
  • If you had Eclipse open while doing this, restart it so that it can pick up the new system path values.

We're now ready for some C development. Callisto comes with two project types for this: "Standard Make C Project" and "Managed Make C Project". The difference is simple. With the standard project type, you are responsible for the compilation, make, build, linking etc that is required for C development. The managed project takes care of all this for you automatically. Let's code and run a "Hello world" C program.

Create a new project, go to "File->New->Project..". Choose "C->Managed Make C project". Name the project "HelloWorldC" and leave all other options at default. Click on "Next and Finish".

Now that we have created the project, let's add a source code file. Select the HelloWorldC project in the Navigator. Go to "File->New->Other.." and choose "C->Source file". Name your file "hello.c" and click on "Finish". You will now have the empty source code file open. Paste the following code into it:

#include <stdio.h>
int main(void) {
printf("Hello, world C!\n");
return 0;
}

When you save the file (Ctrl+S), the magic happens. Eclipse will trigger GCC and make to compile, build and link your file automatically. To run your project, right-click on the "HelloWorldC" project in the Navigator, choose "Run as->C/C++ local application". If this option does not appear the first time, go to the "Run.." menu instead, select "C/C++ local application". If not entered by default, link the run settings to "HelloWorld.exe", which was generated by Eclipse automatically. The output of the run will be visible for you in the console pane:

HelloWorld in C++

Creating and running a C++ project works almost the same as a C project. Note that it also requires GCC and make on the system path. Take notice of the following differences when creating and running HelloWorld for C++:

  • Choose "Managed Make C++ Project" when creating the new project
  • Name your project "HelloWorldC++"
  • Name the source code file "hello.cpp"
  • Use the following code for the source file: #include <iostream>
    using namespace std;
    int main ()
    {
    cout << "Hello World C++!";
    return 0;
    }
  • All the rest works the same as the C project, save your file and run it as a local C/C++ application

HelloWorld in J2EE

After a proper installation of Callisto, nothing extra needs to be installed to code your J2EE project. Running it is a different thing. Eclipse does not come with a J2EE server to run and test your code. You are required to install one yourself, i.e. Tomcat. You also need to make sure that the J2EE server supports the J2EE version that you are using to code your projects. The setup of the J2EE server is out of scope for this article, yet two of my other articles may assist you in this step:

Let's go through the exercise of creating a simple J2EE application with a servlet that prints out "HelloWorld":

  • Go to "File->New->Project..". Select "Web->Dynamic Web Project".
  • Name your project "HelloWorldJ2EE" and click on "Finish"
  • Add a new servlet by choosing "File->New->Other->Web->Servlet".
  • Name your servlet "HelloWorldJ2EE" and click on "Finish".
  • With the servlet source file open, add the following line at the top of the file: import java.io.*; Next, scroll down to the "doGet" method and place the following lines of code in this method: PrintWriter pw = response.getWriter();
    pw.println("Hello World J2EE!");
  • Save the file
  • As mentioned before, running a J2EE application requires a J2EE server. Setting up such a server is out of scope for article.

HelloWorld in PHP

Callisto does not come with any PHP plugins, so we will need to install it seperately. Luckily this is very easy:

  • Go to "Help->Software updates->Search for new features to install" and click on "Next".
  • Click on "New remote site" and fill out "PHP Eclipse" as the name, and "http://phpeclipse.sourceforge.net/update/releases" as the URL:
  • Next, be sure to tick the PHP Eclipse site and click on "Finish". The available updates will be shown. Simply select to install them.

PHP Eclipse allows you to create PHP projects, files, and it offers auto-completion of PHP code. In terms of running your PHP application it assumes you have Apache, PHP and MySQL running locally. The plugin simply gives you links to start and stop these servers. If you do not have these servers installed on your Eclipse machine, they will not work. It is your own responsibility to install them. I personally dislike local PHP development, as I prefer it to be on a Linux server. Therefore, the following instructions might be a bit different compared to your own setup.

To create a new PHP project, go to "File->New->Project.." and choose "PHP->PHP Project". Name your project "HelloWorldPHP". If you run your PHP server on your Eclipse machine, you can leave the "Location" field at its default value. If your like me, and have your PHP source code on a remote server, change the location. I use Samba to allow me to connect to my remote linux machine through a shared drive.

After creating the PHP project, create a PHP file. Go to "File-New->Other.." and choose "PHP->PHP file". Name it "hello.php" and click on "Finish". In the source code file that opens, place your cursor between the PHP tags and hit Ctrl+space to check if code completion works. Next, place the following line of code between the tags: echo("Hello, world PHP!\n");

Save your file and notice how it instantly tries to open it in the "PHP Browser" console in the bottom pane. By default it will try to open it on localhost, which fails for me, since I have LAMP installed on a remote machine. You can alter the server used to open the PHP file in the project properties (right-click on "HelloWorldPHP" in the Navigator and choose "properties").

Conclusion

I think Eclipse Callisto is a great release. You will be able to setup multiple development environments seamlessly in a hour. The typical complaint about Eclipse's performance seems to be irrelavant nowadays too. It's startup time on my basic laptop was only 5 seconds.

The moral behind the article I find to be much more important. Do not stick to a single development platform. It is ok to specialize in one, but you should always keep your eyes open to other platforms. Not only will this make you a great programmer, it is also becoming a neccessity. To succeed in the current and future market, you need to be flexible and broadly skilled. Eclipse Callisto, and hopefully this article, can give you a head start. The rest is up to you.

Update: if J2EE, C/C++ and PHP isn't enough, you can also add Ruby on Rails to your Eclipse IDE. This IBM article explains how.

Share |

Comments: 16
Reviews: 11
Average rating: rating
Highest rating: 5
Lowest rating: 4

COMMENT: BEN PERALES email

JUL 8, 01:56:46 AM

comment » Many thanks for this very informative, very detailed article of yours, Ferdy. Well done. «

COMMENT: ROMAN KOPAC emailhomepage

JUL 8, 23:50:29

comment » Simple, clear, informative, illustrative... Thank you, Ferdy. «

COMMENT: EVAN WILSON emailrating

JUL 19, 05:36:39 AM

comment » Great article, my friend. I've never tried working with PHP in Eclipse and I must say that I find it quite nice. Thanks to you. 01 «

COMMENT: MEPHISTO rating

SEP 30, 07:27:40 AM

comment » Thanks - very nice walkthrough. «

COMMENT: JACK LITTLE emailhomepagerating

FEB 22, 11:54:08 PM

comment » Thank you. Excellent - You made is a walk in the park. «

COMMENT: FAISAL homepagerating

MAY 6, 12:40:39 PM

comment » Excellent tutorial !! «

COMMENT: LIAM homepagerating

JUN 14, 10:01:57

comment » Excellent! Now onto your OpenGL tutorial :) «

COMMENT: K4F rating

OCT 10, 12:40:46 AM

comment » nice review «

COMMENT: DENYOS rating

OCT 23, 07:05:43 PM

comment » Great tutorial! Now i can finally enjoy the power of linux because I have 1! IDE for all languages i wish to use. 18 «

COMMENT: JACK rating

NOV 15, 04:18:53 PM

comment » very good tutorial. Had a problem the first time because of the old link to the runtime binaries. The new page of the runtime binaries is eclipse.org/downloads/moreinfo/custom.php, this is on November 15 2007. «

COMMENT: NEW_TO_LINUX rating

FEB 23, 2008 - 05:45:24 PM

comment » Well, that was all I wanted to start programming in Linux. Thanks! «

COMMENT: TANMOY DEB emailrating

JUL 2, 2008 - 08:57:21 AM

comment » Thanks for the good helping hand tutorial. WAS very very helpful for me. 28 28 «

COMMENT: DOMINIC

JAN 28, 2009 - 05:32:58 AM

comment » You are a saint...thanks you «

COMMENT: SENTHIL MURUGAN email

FEB 20, 2009 - 06:17:16 PM

comment » ITs too cool for such a freshers like me. thank u very much for tour contribution. 01 «

COMMENT: GURIA

JUN 28, 2009 - 13:20:48

comment » Thank you very much. I think that it is very useful manual wich help me. 01 01 01 «

COMMENT: GURIA rating

JUN 28, 2009 - 13:22:24

comment » i forgot rate it 18 of course awesome «

RATE THIS CONTENT (OPTIONAL)
Was this document useful to you?
 
rating Awesome
rating Good
rating Average
rating Poor
rating Useless
CREATE A NEW COMMENT
required field
required field HTML is not allowed. Hyperlinks will automatically be converted.