Eclipse Guide
Eclipse Guide
Developer’s Guide
1
Table of Contents
The Basics
Tips
1
Starting eclipse
When you start eclipse, the first prompt you will get is to
enter the directory for your workspace. This is the area that
you will be creating all of your projects (ex: Hello World When eclipse is finished starting up, you will
project, Calculator project, etc). You can keep the default. see this window. You can close it.
2
How Do I Create a New Java Project?
(If you don’t see Java Project, select File > New > Other.
From there select Java Project and click Next.)
3
How Do I Create a New Java Project?(step 2)
Give the project a name (Start with a letter. Typically it’s just
using letters (no spaces). You can add numbers (ex:
CalculatorExample2).
Click Finish
4
How Do I Create a New Java Project?(cont)
The screen will look like this. If you click the triangle next to your project, it will expand. You will see the following
folders: src, JRE System Library, .settings. You will only be using src. If you try to expand that one, you won’t see
anything since you haven’t created any classes, yet.
5
How Do I Create a Generic Java Class?
Note: If you are creating a servlet (ex: HttpServlet), see “How do I create a servlet?”
Right click src (this holds all of your package and classes).
Select New > Class.
7
How Do I Auto-generate Getters and Setters?
First create all of your variables in your class.
8
How Do I Auto-generate Getters and Setters? (cont)
Right click your class. Select Source > Generate Getters and Setters
9
How Do I Auto-generate Getters and Setters? (cont)
If you want to create getters and setters for all variables click “Select All”. (Usually you want to create
getters and setters for all variables). Then select OK.
10
How Do I Auto-generate a Constructor That Has
Parameters That Get Passed In?
Note: By default, all classes have an empty constructor. For example, for this
class you can create a new Employee object by doing:
11
How Do I Auto-generate a Constructor That Has
Parameters That Get Passed In? (cont)
Right click the class. Select Source > Generate Constructor using Fields
12
How Do I Auto-generate a Constructor That Has
Parameters That Get Passed In? (cont)
All variables will be selected by
default. If you want to pass in all of
the parameters (you usually do),
just click OK.
14
How Do I Run an Executable Class?
If you have a class with a main method, you can run it by right clicking the class and selecting
Run As > Java Application
15
How Do I Run an Executable Class? (cont)
Any
System.out.println
messages will be
displayed in the
console.
16
How to Use Quick Fix to Import A Class
Right click the red x (in the above example, it’s next to the 5) and select Quick Fix.
17
Viewing Syntax Errors
You can hover over a red x to see what the error is.
18
How to zip your Java project or Java classes
Right click your package and select Export. Under
the General folder, select Archive File and click
Next.
19
How to zip your Java project or Java classes
For the Coding test, you’ll want to just select the src file. If it’s a web project, you’ll want everything! Make
sure the “Save in zip format” is selected. Change the archive file name or directory if desired. Click Finish.
Java Web
Test Project
=> =>
20
How to Unzip a Java Project and Import it into Eclipse
Right click the file (it’ll probably be in your downloads). Select Extract All…
21
How to Unzip a Java Project and Import it into Eclipse
Browse and look for your workspace. Click OK and extract.
22
How to Unzip a Java Project and Import it into Eclipse
In Eclipse, select: File > Open Projects from File System…
Click Finish.
23
Eclipse
Tips
24
Tip: Get a List of Methods for a Class
In this example, we set the object nums to a new ArrayList. To find out what methods are available,
you can type the variable followed by a period and wait.
You will see the list of methods (with their signatures) and more details about that method. You can
scroll through the list of methods. To get information on another method in this list, click it once.
To choose to use that method, click it twice!
25
Tip: Get a List of Methods for a Class (cont)
Many of the most common methods are at the top of the list.
To view the rest of the details for a particular method (the details are on the left side), click tab
twice. You can click the scroll bar next to the methods to scroll through the methods again.
26
Tip: Get a List of Method Signatures
Type the method followed by the open parenthesis. Then press Ctrl + Shift + Space.
In this example, there are three signatures for add. One takes an array of Integer, one takes two ints, and
one takes an ArrayList of Integer.
27
Tip: Find a Matching Bracket
Once you start writing more complicated code, you may have a lot of nested blocks like the code
shown below. If you want to find where the matching bracket is (in this example, we want to see
the starting bracket), put the cursor at the end of a bracket and press
28
Tip: How to Quickly Add a Javadoc
To quickly add a Javadoc, type /** and hit enter!
29
Eclipse
Beyond The Basics
30
How Do I Add Database Classes to a Java Project?
The oracle database classes all reside in a jar file called classes12.jar. To add that jar file to your project,
do the following:
31
How Do I Add Database Classes to a Java Project? (cont)
32
How Do I Create a New Static Web Project?
Static web projects are for simple web apps with (If you don’t see Java Project, select File > New > Other.
HTML, CSS, and Javascript. From there look for the Web folder and open it. Then
select Static Web Project and click Next.)
33
How Do I Create a New Dynamic Web Project?
Select File > New > Dynamic Web Project (If you don’t see Java Project, select File > New > Other.
From there look for the Web folder and open it. Then
select Dynamic Web Project and click Next.)
34
How Do I Create a New Dynamic Web Project? (cont)
Then type in your project name and select “2.5” from the Dynamic web module version drop down menu.
Click Finish.
35
How Do I Create a New Dynamic Web Project? (cont)
When you expand the project, you will see a lot more folders. Your java source goes under Java Resources >
src. Your HTML, CSS, JS, and JSP goes under WebContent.
• index.html
• index.htm
• index.jsp
• default.html
• default.htm
• default.jsp
36
How Do I Add Database Classes to a Dynamic Web Project?
Using Windows File Explorer, go to the directory where your ojdbc6.jar resides (it might be in your
Downloads folder). Right click it and select copy.
Then go into your Dynamic Web project and under WebContent > WEB-INF > lib, right click there and select
paste!
37
How Do I Add Database Classes to a Dynamic Web Project?
(cont)
Now right click your project and select Build Path > Configure Build Path
38
How Do I Add Database Classes to a Dynamic Web Project?
(cont)
Select the location of your ojdbc6.jar and click OK. Then click Apply from the “Java Build Path” window and
then OK.
We’re now
using
ojdbc6.jar
instead of
clases12.jar!
39
How Do I Create a Servlet?
(if you don’t see it, select New > Other . Look for the
Right click src and select New > Servlet Web folder and expand it. Select Servlet)
40
How Do I Create a Servlet? (cont)
Enter in the package name and name of the servlet (the name should end in “Servlet”). Click NEXT!
41
How Do I Create a Servlet? (cont)
Under URL mappings, add the string that matches the action on your form. Click OK and then click Finish
42
How Do I Create a Servlet? (cont)
Note: This will update your web.xml with the servlet information and the servlet-mapping (your web.xml is located under
WebContent > WEB-INF).
44
How Do I Add a Tomcat Server? (cont)
Click on the link that says “No servers are available.
Click on this link to create a new server”.
(yeah, it’s a very descriptive link!)
45
How Do I Add a Project to a Tomcat Server?
Right click the Tomcat server and select Add and Remove. Select your project and click Add. You will see your
project show up under “Configured”. Then click Finish!
46