Click here to Skip to main content
15,867,594 members
Articles / Web Development / Apache

Set Up Eclipse for Java Development

Rate me:
Please Sign up or sign in to vote.
4.88/5 (9 votes)
17 May 2014CPOL7 min read 93.9K   21   7
This is a study note on setting up Eclipse IDE for Java development.

Introduction

This is a study note on setting up Eclipse IDE for Java development.

Background

I have worked on both Java and Microsoft .Net in my career and I like both of them. Recently I noticed some exciting activities in the Java and the open source society and started to pick up Java again. The first thing that I do is to pick an IDE. According to a recent study, Eclipse is the most popular IDE for Java development. This study note is a step by step instruction on how to set up Eclipse. In this study note, I will set up Eclipse on a windows 64-bit computer. If you are using Linux, you are probably already an expert on Eclipse. If not, this study note should at least have some reference values for you, because the overall principles are the same.

Eclipse is a Java application, so the first step to set up Eclipse is to install the Java Run-time Environment.

Install the Java Run-Time Environment

If you do not already have a desired Java Run-time environment on your computer, you will need to install one. You can go to the Oracle website to download it. You can choose to download either a JRE or a JDK. For most of the functions in Eclipse, a JRE should be sufficient. But I noticed that if you want to develop a Dynamic Web Project, and if you want to debug it with a J2EE Preview server, you will need a JDK to power the Eclipse IDE. In this study note, I chose the JDK version (Java SE 8U5) for windows 64-bit computers and installed it to the default location.

Image 1 The installer added both JRE and JDK to the computer. We will need to remember this location and later configure Eclipse to use this particular version of Java Run-time environment.

Download the Eclipse

You can go to the official Eclipse website to download the desired version of Eclipse. In this study note, I downloaded the Eclipse Kepler (4.3.2). There are many Eclipse packages to choose from. Since I will be doing a lot of web application development, I choose the "Eclipse IDE for Java EE Developers" for windows 64-bit computers. The following is the downloaded zip file from the Eclipse website.

Image 2

After downloading the zip file, you can extract this zip file to any location on your computer.

Image 3

The "eclipse.exe" file is the file to launch Eclipse on a windows computer. But before lunching Eclipse, we need to configure the desired version of the Java Run-time environment to power it.

Choose the Desired Java Run-time to Launch Eclipse

It is very common that you have multiple versions of Java Run-time environment on your computer. It is desirable to specify the desired one to power Eclipse. According to the Eclipse documentation, there are three common methods to specify the Java Run-time environment.

  • If a Java Run-time environment is installed in the eclipse/jre directory, Eclipse will use it;
  • Otherwise the Eclipse launcher will consult the "eclipse.ini" file and the system path variable. Eclipse does not consult the JAVA_HOME environment variable;
  • You can also choose to directly invoke the desired JVM to start the "jar" file that launches Eclipse. For the version of Eclipse in my study note, it is the "org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar" file in the "plugins" folder.

According to the Eclipse documentation, the most recommended method is to specify the desired Java Run-time in the "eclipse.ini" file.

Image 4

In my study note, I added the "-vm" parameter in the "eclipse.ini" file pointing to the JVM that I just installed. After saving the "eclipse.ini" file, we are ready to launch Eclipse.

Launch Eclipse

Eclipse organizes the code in "workspaces". A "workspace" is a folder where Eclipse put all your code for your projects. To launch Eclipse, let us create an empty folder called "FirstEclipseWorkspace" anywhere in the computer.

Image 5

In the windows environment, we can double click the "eclipse.exe" file to launch Eclipse.

Image 6

During the launching process, Eclipse will ask us to select a "workspace". We can browse to the folder just created and click the "OK" button.

Image 7

Since the "FirstEclipseWorkspace" folder is empty, Eclipse shows us the welcome page. To double check that Eclipse is indeed powered by the desired version of JVM, we can click on the "Help" menu item and then click on "About Eclipse" to open the "About Eclipse" window.

Image 8

Image 9

In the "About Eclipse" window, clicking on the "Installation Details" button will open the "Eclipse Installation Details" window.

Image 10

We can see that the JVM that powers this instance of Eclipse is indeed the JVM that we specified in the "eclipse.ini" file.

Create a Simple Dynamic Web Project

We have successfully launched Eclipse, now we will create a simple dynamic web project in Eclipse. I will use Tomcat to debug this project. If you do not have a installation of Tomcat on your computer, Eclipse can install it for you and you will need to create a folder on your computer for Eclipse to install Tomcat. Since I will use Tomcat 7 for the development work, I named the folder "Tomcat7".

Image 11

After creating the Tomcat installation folder, we can create the web project in Eclipse using the project wizard provided by Eclipse.

Image 12

The project wizard can be launched from the Eclipse menu "File" -> "New" -> "Dynamic Web Project".

Image 13

Let us give the project a name "SimpleWeProject" and configure the project to use Tomcat. Clicking on the "New Runtime" button will bring us the "New Server Runtime Environment" wizard.

Image 14

We can select "Apache Tomcat v7.0" and click the "Next" button to set up the Tomcat server for the project.

Image 15

Since we do not have a Tomcat installation on the computer yet, we can click the "Download and Install" button to install Tomcat in the "Tomcat7" folder that we have created earlier. After the successful installation of Tomcat, The project wizard should look as the following.

Image 16

Clicking the "Next" button "twice" we will be ready to finish creating the "dynamic web project" using the "New Dynamic Web Project" wizard.

Image 17

Make sure to check the "Generate web.xml deployment descriptor". By checking this checkbox, the wizard will add the "web.xml" file in the project, which is used to configure a lot of important information about the web application. After clicking the "Finish" button, the wizard will create an empty "dynamic web project" in Eclipse.

Image 18

Add a Simple Java Server Page to the Project

Image 19

To add a JSP page to the project, we can right click on the "WebContent" folder -> "New" -> "JSP File" to launch the "New JSP File" wizard.

Image 20

Give the JSP file the name "index.jsp" and click the "Finish" button, the JSP file is added to the project.

Image 21

We can then edit the "index.jsp" file. To keep this project as simple as possible, the only thing that "index,jsp" does is to display the text "Eclipse is cool!" in the browser.

Image 22

Run the Web Project in Eclipse with Tomcat

To run the web project in Eclipse with Tomcat, we can right click on the project "SimpleWeProject" -> "Run As" -> "1Run on Server". A pop up window will show up to let us to select the server to run the application.

Image 23

Since we have configured the "Target runtime" of this project as "Apache Tomcat v7.0", we can take all the default selections and click the "Finish" button to run the web application in a web browser embedded in Eclipse.

Image 24

Of course, you can also load the page into a standalone browser. The following picture shows the web page displayed in Firefox.

Image 25

Points of Interest

  • This is a study note on setting up Eclipse IDE for Java development.
  • In this study note, we created a simple "dynamic web project" and run it in Eclipse with a Tomcat server.
  • This study note is based on a windows computer, but the general concept is the same as in any other platforms, such as Linux.
  • I hope you like my postings and I hope this article can help you one way or the other.

History

First revision - 5/16/2014.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
I have been working in the IT industry for some time. It is still exciting and I am still learning. I am a happy and honest person, and I want to be your friend.

Comments and Discussions

 
Questionerror about tomcat server Pin
manikand19-Mar-15 23:35
manikand19-Mar-15 23:35 
AnswerRe: error about tomcat server Pin
Dr. Song Li20-Mar-15 2:59
Dr. Song Li20-Mar-15 2:59 
QuestionRe: error about tomcat server Pin
manikand22-Mar-15 16:42
manikand22-Mar-15 16:42 
AnswerRe: error about tomcat server Pin
Dr. Song Li20-Mar-15 3:00
Dr. Song Li20-Mar-15 3:00 
If you take a look at the console window in Eclipse, it may have more information for you. I Hope this helps ...
Suggestionidea Pin
Member 109276516-Jul-14 6:52
Member 109276516-Jul-14 6:52 
QuestionFindBugs Pin
Rosenne18-May-14 23:17
Rosenne18-May-14 23:17 
QuestionGood Article Pin
M@dHatter16-May-14 18:44
M@dHatter16-May-14 18:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.