1. Eclipse Overview
Eclipse is created by an Open Source community and is used in several different areas, e.g. as a development environment for Java or Android.
The Eclipse project is governed by the Eclipse Foundation. The Eclipse Foundation is a non-profit, member supported corporation that hosts the Eclipse projects and helps to cultivate both an open source community and an ecosystem of complementary products and services.
Eclipse roots go back to 2001. Today it is the leading development environment for Java with approx. 65% marketshare.
Eclipse can be extended with additional functionalities. Several Open Source projects and companies have extended Eclipse with additional components. It is also possible to use Eclipse as a basis for creating general purpose applications (Eclipse RCP).
This description focuses on using Eclipse as a Java development environment.
Eclipse requires an installed Java Runtime. I recommend to use Java 7 (also known as Java 1.7) or Java 6.
Java comes in two flavors, the Java Runtime Environment (JRE) and the Java Development Kit (JDK). The JRE contains only the necessary functionality to start Java programs, while the JDK contains in addition the development tools.
Eclipse contains its own development tools, e.g. Java compiler. Therefore for this tutorial it is sufficient to use the JRE.
The JDK is required if you compile Java source code outside Eclipse and for advanced development scenarios. For example if you use automatic builds or if you develop web development. These scenarios are not covered in this tutorial.
Java might already be installed on your machine. You can test this by opening a console (if you are using Windows: Win+R, enter "cmd" and press Enter) and by typing in the following command:
If Java is correctly installed you should see some information about your Java installation. If the command line return the information that the program could not be found, you have to install Java. A Google search for "How to install Java on ..." should result in helpful links. Replace "..." with your operating system, e.g. Windows, Ubuntu, Mac OS X, etc.
Java comes in two flavors, the Java Runtime Environment (JRE) and the Java Development Kit (JDK). The JRE contains only the necessary functionality to start Java programs, while the JDK contains in addition the development tools.
Eclipse contains its own development tools, e.g. Java compiler. Therefore for this tutorial it is sufficient to use the JRE.
The JDK is required if you compile Java source code outside Eclipse and for advanced development scenarios. For example if you use automatic builds or if you develop web development. These scenarios are not covered in this tutorial.
Java might already be installed on your machine. You can test this by opening a console (if you are using Windows: Win+R, enter "cmd" and press Enter) and by typing in the following command:
java -version
If Java is correctly installed you should see some information about your Java installation. If the command line return the information that the program could not be found, you have to install Java. A Google search for "How to install Java on ..." should result in helpful links. Replace "..." with your operating system, e.g. Windows, Ubuntu, Mac OS X, etc.
To install Eclipse download the package "Eclipse IDE for Java Developers" from the websitehttp://www.eclipse.org/downloads and unpack it to a local directory.
The download is a "zip" file. Most operating system can extract zip files in their file browser, e.g. Windows7 via right mouse click on the file and selecting "Extract all...". If in doubt, search via Google for "How to unzip a file on ...", again replacing "..." with your operating system.
Use a directory path which does not contain spaces in its name, as Eclipse sometimes has problems with that.
After unpacking the download, Eclipse is ready to be used; no additional installation procedure is required.
The download is a "zip" file. Most operating system can extract zip files in their file browser, e.g. Windows7 via right mouse click on the file and selecting "Extract all...". If in doubt, search via Google for "How to unzip a file on ...", again replacing "..." with your operating system.
Use a directory path which does not contain spaces in its name, as Eclipse sometimes has problems with that.
After unpacking the download, Eclipse is ready to be used; no additional installation procedure is required.
To start Eclipse double-click on the file
Eclipse will start and show the Welcome page. Close the welcome page by pressing the "X" beside "Welcome".
Eclipse provides
eclipse.exe
(Microsoft Windows) or eclipse
(Linux / Mac) in the directory where you unpacked Eclipse. The system will prompt you for a workspace. The workspace
is the place where you store your Java projects (more on workspaces later). Select an empty directory and press Ok.Eclipse will start and show the Welcome page. Close the welcome page by pressing the "X" beside "Welcome".
3. Eclipse UI Overview
Perspectives
, Views
and Editors
. Views
and Editors
are grouped intoPerspectives
. All projects are located in a workspace
.The
You can predefine the workspace via the startup parameter
Please note that you have to put the path name into double quotes.
To see the current workspace directory in the title of Eclipse use
workspace
is the physical location (file path) you are working in. You can choose the workspace during startup of Eclipse or via the menu ( → → . All your projects, source files, images and other artifacts will be stored and saved in your workspace.You can predefine the workspace via the startup parameter
-data path_to_workspace
, e.g.c:\eclipse.exe -data "c:\temp"
.Please note that you have to put the path name into double quotes.
To see the current workspace directory in the title of Eclipse use
-showLocation
as an additional parameter.A
You can change the layout and content within a
For Java development you usually use the
A common problem is that you mis-configured your
Perspective
is a visual container for a set of Views
and Editors
.You can change the layout and content within a
Perspective
, for example by opening or closing Views
orEditors
, changing their size and position and more. Eclipse allows you to switch to another perspective via the menu → → .For Java development you usually use the
Java Perspective
, but Eclipse has much more predefinedPerspectives
, e.g. Debug, Git Repositories, CVS Repositories.A common problem is that you mis-configured your
Perspective
, e.g. by closing a View
. You can reset aPerspective
to its original state via the menu → .A
View
is typically used to navigate a hierarchy of information or to open an Editor
. Changes in a View
are directly applied to the underlying data structure.Editors
are used to modify elements and are typically text editors. An Editor
can have code completion, undo / redo, etc. To apply the changes in an editor to the underlying resource, e.g. Java source file, you have to save.The default
On the left hand side, this perspective shows the "Package Explorer"
For example to open a Java source file, open the tree under
The following picture shows the Eclipse IDE in its standard Java perspective. The "Package Explorer" is on the left. In the middle you have the open
To the right and below the editor area you find more
Perspective
for Java development can be opened via → → .On the left hand side, this perspective shows the "Package Explorer"
View
which allows to browse your Java projects and to select the components you want to work on via double-click.For example to open a Java source file, open the tree under
src
, select the corresponding .java
file and double-click it. This will open the file in an Editor
.The following picture shows the Eclipse IDE in its standard Java perspective. The "Package Explorer" is on the left. In the middle you have the open
Editor
for a Java source file. If several Editors
would be open, they would be stacked in the same place and you could switch between them by clicking on the next Editor
. All editors share the same part of the Eclipse IDE; this part is called the "editor area".To the right and below the editor area you find more
Views
which were considered useful by the developer of the perspective. For example the "Console" view shows the output of System.out
statements in your code.The Package Explorer allows displaying the associated file from the currently selected editor. For example if you working on
To activate this behavior, press the button "Link with Editor" in the "Package explorer"
Foo.java
and you change in the editor to Var.java
then the corresponding file will be selected in the the "Package explorer" View
.To activate this behavior, press the button "Link with Editor" in the "Package explorer"
View
.Sooner or later you will run into problems with your code or your project setup. To view the problems in your project you can use the "Problems"
You can configure the content of the "Problems"
View
which is part of the standard Java Perspective. If it is closed you can open it via → → .You can configure the content of the "Problems"
View
. For example, to display the problems from the currently selected project, select "Configure Contents" and set the Scope to "On any element in the same project".The following describes how to create a minimal Java program using Eclipse. It is tradition in the programming world to create a small program which writes "Hello World" to the console. We will adapt this tradition and will write "Hello Eclipse!" to the console.
Select from the menu → → . Enter
Press finish to create the project. A new project is created and displayed as a folder. Open the
de.vogella.eclipse.ide.first
as the project name. Select the flag "Create separate folders for sources and class files".Press finish to create the project. A new project is created and displayed as a folder. Open the
de.vogella.eclipse.ide.first
folder and explore the content of this folder.Create a new
Select the folder
package
. A good convention is to use the same name for the top package and the project. Create therefore the package de.vogella.eclipse.ide.first
.Select the folder
src
, right click on it and select → .We will now create a Java class. Right click on your package and select → .
Enter
This creates a new file and opens an
Enter
MyFirstClass
as the class name and select the flag "public static void main (String[] args)".This creates a new file and opens an
Editor
to edit the source code of this file. Write the following code.
package de.vogella.eclipse.ide.first;
public class MyFirstClass {
public static void main(String[] args) {
System.out.println("Hello Eclipse!");
}
}
Now run your code. Right click on your Java class and select → .
Finished! You should see the output in the console.
Finished! You should see the output in the console.
To run your Java program outside of Eclipse you need to export it as a
Select your project, right click on it and select
Select JAR file, select next. Select your project and maintain the export destination and a name for the jar file. I named it
Press finish. This creates a jar file in your selected output directory.
jar
file. A jar
file is the standard distribution format for Java applications.Select your project, right click on it and select
Export
.Select JAR file, select next. Select your project and maintain the export destination and a name for the jar file. I named it
myprogram.jar
.Press finish. This creates a jar file in your selected output directory.
Open a command shell, e.g. under Microsoft Windows select → and type
Switch to your output directory, by typing
To run this program you need to include the jar file in your
If you type the command from above and are in the correct directory you should see the "Hello Eclipse!" output on the console.
Congratulations! You created your first Java project, a package, a Java class and you ran this program inside and outside Eclipse.
Source Link:http://www.vogella.de/articles/Eclipse/article.html
cmd
and press enter. This should open a console.Switch to your output directory, by typing
cd path
. For example if your jar is located in c:\temp
type cd c:\temp
.To run this program you need to include the jar file in your
classpath
. The classpath
defines what Java classes are available to the Java runtime. You can add a jar
file to the classpath with the -jar
option.
java -classpath myprogram.jar de.vogella.eclipse.ide.first.MyFirstClass
If you type the command from above and are in the correct directory you should see the "Hello Eclipse!" output on the console.
Congratulations! You created your first Java project, a package, a Java class and you ran this program inside and outside Eclipse.
Source Link:http://www.vogella.de/articles/Eclipse/article.html