Install eclipse
Step 1: Download and install eclipse latest version into the “c:\tools” folder from
http://www.eclipse.org/downloads/
It is an IDE (i.e. Integrated Development Environment). This tutorial downloads Eclipse Neon. Get the EE (Enterprise Edition).
Select “c:\tools” as the target folder.
Launch it.
Step 2: It is a good practice to keep your eclipse workspace separate from where your projects. This will not tie up your projects or tutorials with an IDE. What if you want to use your projects or tutorials with NetBeans?
Create a new folder “c:\workspace” to store the eclipse metadata.
Exit out of the following welcome tab by clicking the “x”.
Import the existing non maven project folders
Step 1: Import the project “C:\projects\beginner-proj-1” that was created in the “getting started with Java” tutorial as the existing system folder.
Do the same for the folder “C:\projects\beginner-proj-2”
Step 2: Why do you see an error? It is because “beginner-proj-1” depends on “beginner-proj-2” as you know that
1 2 3 4 5 6 7 8 9 10 11 12 |
package com.main; //write .class to subfolders com/main import com.service.HelloService; public class HelloWorld { public static void main(String[] args) { System.out.println("My first java code without IDE & with packages"); HelloService.print(); } } |
depends on “com.service.HelloService”, which is in the project “beginner-proj-2”
1 2 3 4 5 6 7 8 9 |
package com.service; //write class file to subfolder com/service public class HelloService { public static void print() { System.out.println("A class in another package is called"); } } |
Step 3: We can fix the issue with “build path” set up. Right mouse click on the project “beginner-proj-1”, and select “properties“, and set the dependency.
Step 4: Now, you can run the “com.main.HelloWorld” by right mouse clicking on it and then select “Run as” and then “Java Application”.
Create a new Java project within eclipse
Step 1: Select from the top menu “File” –> “New” –> “Project…” –> and then “Java Project” from the pop up. Call the project “learn-java”.
Step 2: Right mouse click on “src“, and then do “New” –> Package, and name the package “com.mytutorial“.
Step 3: Right mouse click on “com.mytutorial“, and then select “New” –> Class, and name it “HelloWorld“. Type the following code by double clicking on the “HelloWorld.java”.
1 2 3 4 5 6 7 8 9 |
package com.mytutorial; public class HelloWorld { public static void main(String[] args) { System.out.println("My first java code with IDE & packages"); } } |
Step 4: You can right click on “HelloWorld.java” and run it.
Next Java Beginner Tutorial: Getting started with Eclipse IDE & Maven.