Eclipse Survival Guide
This first section has the must know items to survive in Eclipse.
Eclipse Version: Helios Service Release 2
(hopefully works with: Mars.1, Neon.1)
General Eclipse as Needed Info
Eclipse Documentation
Eclipse General Info
- Eclipse version - Help, About Eclipse
- JVM version used to run programs:
- Launch Eclipse. Help, About Eclipse,
- Click "Installation Details"
- Click the tab "Configuration"
- JRE version used to run your programs.
- java.version
- java.vm.version
- JDK version used to compile java programs using
"javac.exe"
- Look for the property: java.library.path
java.library.path=C:\Windows\system32;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;
etc.....
C:\java\jdk1.6.0_21\bin
FYI - Possible Errors:
- Memory problems:
- Fix:
Modifiy your eclipse.ini file.
-Xms40m
-Xmx512m
-XX:PermSize=512m
- Class Diagram Error in the .java file caused when
there is a many relationship and the JDK Compiler is less than
5.0.
- Multiple markers at this line
- The type Collection is not generic; it cannot be
parameterized with arguments <ContractHourly>
- Syntax error, parameterized types are only available if
source level is 5.0
- Watch point: Company [access and modification] -
contractorHourly
- Fix:
In Eclipse, at the top click
Window, Preferences, expand "Java", "Compiler" then click on
"Compiler".
JDK compliance level: 5.0 (or greater)
If you want to configure a specific project then click
"Configure Project Specific Settings".
Must Know ASAP
Help Me NOW!
- Reset Perspective - Window->Reset Perspective - if
you mess up your view, known as a perspective, you can reset it
back to the default or last saved perspective state.
- Full screen - double-click on a tab and it will go full
window. "double-click" again and it will return back to
it's position in the perspective.
TODO: I need to
make a 1-2 page cheat sheet.
Editor
- Basic Items - learn now!
- Key Assistant - click "Help", "Key Assistant"
(Ctrl-Shift-L) - will show you the short cut keys.
- To Lower Case - Ctrl-Shift-Y
- To Upper Case - Ctrl-Shift-X
- Highlight cursor through next word - Ctrl-Shift-Right
- Highlight cursor through prior word - Ctrl-Shift-Left
- Show Line Numbers in side bar - right click on the side
bar then choose "Show Line Numbers".
- Project Clean - when it looks like Eclipse is having
issues, not recognizing your changes etc.. do the following:
- Rename or Move a file - Right click on the file
name. Choose "Refactor" and then "Rename" or "Move".
- Copy/Paste - <ctrl-c>, <ctrl-v>
- Ctrl+F4 = Close a window.
- Ctrl+L = Goto line #
- Ctrl+Shift+F = Format code. Formats all code or
highlighted code.
- Ctrl+/ = Comment/Uncomment each line individually for
selected text.
- Quick Fix - <ctrl-1> or right click in blank space
of editor and choose "Quick Fix".
- Put cursor on any words underlined in a yellow then
<ctrl-1> to suggest fixes. Then click on a
fix. Great for imports, getter/setter, etc...
- Mark Braces ({}) or Highlight Code in Braces ({}) - you
can see where the beginning and ending brace is for a code
block.
- Put your cursor right after one of the braces ( "{" or
"}" ). The other brace will have a box around it.
- Double-click right after either brace and the code in
the braces will be highlighted.
- Class Code Help
- Class.<ctrl-space> - will display a list of
methods etc...
- <ctrl+space> - Code Templates
- How to use: Type the template then press
<ctrl-space>
ex: sysout<ctrl-space>
The editor will then finish with: System.out.println();
- Find a complete list: Java->Editor->Templates
- Common Code Templates:
- sysout<ctrl-space> = System.out.println();
- main<ctrl-space> - inserts a main method.
- All the conditional & looping commands:
if<ctrl-space>
else<ctrl-space>
switch<ctrl-space>
for<ctrl-space>
while<ctrl-space>
do<ctrl-space>
- Notations - @<ctrl-space>
- try<ctrl-space>
- instanceof<ctrl-space>
- Custom templates - you can create your own templates
too!
- Task Lists
- Eclipse has a way for you to create a list of Tasks
that you need to do.
- How to display Tasks
- Window->Show View->Tasks - this will show
all the tasks. Double click on one and it will open
up the file and take you to that line.
- How to create Tasks - you create a comment followed by
a task tag.
ex: //TODO <your words.....>
- Task Tags (ones that exist already)
- //TODO <your words....> - defaults to a
NORMAL priority
- //FIXME <your words...> - defaults to a
HIGH priority
- //XXX <your words...> - defaults to a
NORMAL priority
- Custom Tasks - you can create your own tasks!
- To create a custom task do the following:
- Java, Compiler, Task Tags
- Click "New", REFACTOR, then choose a
priority: HIGH, NORMAL, LOW
- Ones that I like:
- //REFACTOR - LOW priority.
- Source help
- Right click in white space of the editor, then choose
"Source"
- Generate getters/setters
- many others ....
- Advanced Items - learn now
- Ctrl-F6 - go back (like the back key in the
browser). Goes back one level.
- Ctrl-O - Code Outline - popup a window with an outline of
the Code.
- Ctrl-T - Type Hierarchy - place cursor on a class/method
then <ctrl-t> to show type hierarchy. For
methods will show the implementing methods also!
F4 - will do the same thing but listed in the left panel.
- Declarations - who declares or implements this data type?
- Ctrl-G - lists all declarations in the bottom panel.
- F3 - Open Declaration - place cursor on a class or
method and press F3 to open in the editor that
class/method.
- You can also do that for the Java language classes
if you have configured Eclipse to use the JDK and
not a JRE. (See the ERROR section for
additional notes).
- References - who references this data type?
- Ctrl-Shift-G - shows who references it in the bottom
panel.
- Alt-<up arrow> - move code up
- Alt-<down arrow> - move code down
- Ctrl-F11 - rerun the last thing you ran.
- F11 - rerun in the debugger.
-
Advanced Items - learn later
-
ALT-Shift-L - create a variable with
highlighted code.
Step 1: Enter the following code.
int myIndex = "Michael|Thomas|123 Love
Ln|Atlanta|GA|55555".indexOf("|GA|");
Step 2: Highlight the long string.
Step 3: ALT-Shift-L
Step 4: Type your variable name. Ex: myString
resulting code:
String myString = "Michael|Thomas|123
Love Ln|Atlanta|GA|55555".indexOf("|GA|");
int myIndex = myString.indexOf("|GA|");
-
Open Items - I need to research
-
I need
to finish formatting etc....
-
Refactoring
Right-click over your source code to get the Refactor menu
Rename – rename a package, class, method, field, local
variable
All references will be updated
Move – move static methods or fields
Change Method Signature – modify any aspect of the method
signature
Push Down – move instance variables or methods to a
subclass
Pull Up – move instance variables or methods to the
superclass
Extract Method – extract selected code into a private
method
Any local variables will be passed as parameters to the
new method
Extract Local Variable – select an expression
Any classes created and passed in the expression are
extracted and
assigned to local variables
Inline – references to called code are inlined
Debugger
- Breakpoint - place your mouse on the left side bar, right
click, "Toggle Breakpoint".
- F5 - step in
- F6 - step over
- F7 - step return
- F8 - resume
- Ctrl-F2 - terminate
- Step Filtering - Preferences: Java->Debug->Step
Filtering, click "Use Step Filters", then "Select All", OK
- so that you do not try to enter into the Java
packages. You can add others at this location.
- Error: "Source not found" while in the Debugger.
- Fix: See the "Step Filtering" in this section.
Preferences - (Window->Preferences)
- Each workspace has it's own preferences. To move your
preferences (customized perspective, views, fonts, and other
settings) to another workspace do the following:
- In your current workspace do the following:
File->Export->General->Preferences
- In your new workspace do the following:
File->Import->General->Preferences
- Searching for a preference - just enter the words you desire
to search for in the upper left box.
- Nice to know preference
- Change the font size: General, Appearance, Colors and
Fonts, Basic, Text Font, Edit
(Search Note: fonts)
- Format source on "Save": Java, Editor, Save Action.
Check "Perform the selected action on save"
Check "Format Source Code". (Some like this and some
don't.)
- Optional: Check "Additional actions"
Add final modifier to private
fields
Add missing '@Override' annotations
Add missing '@Override' annotations to implementations
of interface methods
Add missing '@Deprecated' annotations
Remove unnecessary casts
- Line wrapping, set to 120 (default is 80): Java, Code
Style, Formatter, click the "Edit" button, click the "Line
Wrapping" tab
Maximum line width: 120
(Warning: You must change the "Profile Name" to make this
change.)
File Search
- Search->Search
- Workspace - if workspace is selected it will search all
projects in the workspace.
- Working Set - if "Working Set" is selected you can select
which custom set of projects will be searched.
- Create a "Working Set" - Select "Working
Set"->Choose->New->Java, give the "Working Set"
a name and then select the projects.
Create a Project
- How to create a new Java Project
- Click "File", "New", "Java Project"
(If the above is not an option then click "Other",
"General", "Java", "Java Project")
- Project Name: <enter your project name>
- Click "Finish"
- How to create a new Web Project
- Click "File", "New", "Dynamic Web Project"
(If the above is not an option the click "Other", "General",
"Web", "Dynamic Web Project").
- Project Name: <enter your project name>
- Click "Finish"
Creating Files & Folders (JAVA EE perspective)
- folder (also works for a package)
Right click on your project, "New", "Folder"
- file (also works for a class or .java file)
Right click on your project, "New", "File"
- package - create a new one.
Right click on your project, "New", "Other", "Java", "Package"
- class (or .java) - create a new one.
Right click on your project, "New", "Other", "Java", "Class"
Copy a Project
- How to copy a Web Project
- Right click on the project you want to copy. Choose
"Copy".
- Right click on the white space by the list of
projects. Choose "Paste"
- Project Name: <enter your new project name>
- Change the Context Root
- Right click on the project and choose: "Properties",
"Web Project Settings"
- Enter the new context root name.
Eclipse Workspaces
- Here is my suggestion.
Create the following directory: c:\eclipseworkspace
Now create as many subdirectories for each workspace you want to
stick projects into.
- Example of Workspace Directory Names under c:\eclipseworkspace:
(just my naming)
- EclipseTutorialWS - place to play with Eclipse.
- MyStrutsTestWS - place proof of concept or testing
type projects here.
- Struts2OrigWS - place all of the web apps that come
with the Struts2 download.
- Tomcat60OrigWS - place all of the webapps that come
with the Tomcat 6.0 download.
- BookStruts2InActionWS - place all of the webapps that
come with the books download.
- Launch Eclipse and when prompted for the workspace enter
one of them.
ex:
c:\eclipseworkspace\EclipseTutorialWS
ex:
c:\eclipseworkspace\MyStrutsTestWS
- Managing Eclipse Workspaces
- Prompt for workspace on startup - if you accidently
checked to not prompt for workspace and you would like undo
that action do the following:
Windows, Preferences, in the box type "workspace". Click on
the first "workspace".
Uncheck: Prompt for workspace on startup.
- Manage list of Workspaces
- Remove workspaces:
Windows, Preferences, in the box type "workspace". Click
on the first "workspace".
- Increase the number of workspaces to remember. Default
is 5
Windows, Preferences, in the box type "workspace". Click
on the first "workspace".
Change the value
Create a Custom Perspective: JAVA EE (<initials>)
- First step: Choose the JAVA EE perspective
- In the upper right corner click on the small icon by the
perspective name. Choose "Other" and then "JAVA
EE". Now you have screens that have the JAVA EE look
or perspective.
- In the far right corner right click on icon "Java EE" and
choose "Save As".
(Note: If the icon is not there then click the small icon to the
left of it and choose: Java EE)
Name: Java EE (<your initials>) - Put your initials in the
brackets (ex: MT for Michael Thomas)
Click "Ok"
- Right click on "Java EE (??)" and choose "Customize".
Click on the Tabs just to see what can be customized.
Changing Colors and Font
- Text Font Size - Windows, Preferences, then in search
"font".
Click "Colors and Font", expand Basic, click on "Text Font",
Edit, then for Size choose 12, Apply.
(Some times the font is just to small!)
Show View - click Window, Show View
- Add/Remove a View
- Add a View: Window, Show View
- Add Navigator View - Window, Show View, Navigator
- Other popular views:
- Navigator - Navigator is more like windows
explorer
- Console - Eclipse will automatically create
this view when needed.
- Search - Eclipse will automatically create
this view when needed.
- Server - Eclipse will automatically create
this view when needed.
- Remove a View: Click the "X" button in the "Navigator"
view. Now restore it back: Window, Show View,
Navigator.
- Working with Views
- Minimize, Maximize, Normal
- Locate the Project/Navigator view on the left side.
- Click the "Minimize" icon. To restore, click
the icon with 2 pages (normal) and it will reappear.
- Click the "Maximize" icon. To restore, click
the icon with 2 pages (normal) and it will reappear.
- Double click the "Navigator" tab and it will
Maximize. Double click the "Navigator" tab
again and it will "Minimize".
- Play with the other views.
Context Root
- How to change the context root for your webapp. (Tomcat)
Right click on your project, Properties, Web Project Setting,
Context Root
Ex: Project name is: struts2-lab.
http://localhost:8080/struts2-lab - launch the context
root.
Change the context root to: lab
http://localhost:8080/lab
- launch the new context root.
Errors
- F3 (Open Declaration) on a java.lang or classes in the JDK.
- Error
Class File Editor
Source not found
The JAR file C:\Program Files\ ...\lib\rt.jar has no source
attachment.
- Fix - Step 1 - Configure Eclilpse to use the JDK and not
the JRE.
- Window->Preferences->Java->Installed JREs
- Click "Add", "Standard VM", "Next"
- For "JRE Home" click "Directory"
- Locate your JDK directory...
Ex: C:\java\jdk1.6.0_24
- Click "Finish"
- Next check the JDK vs the JRE that is listed.
- Click "Ok"
- Fix - Step 2 - Configure your Project to use the JDK
because it was created with the JRE as the "Installed
JRE". New project should be OK.
- Right click the project's name.
- Choose "Properties", "Java Build Path"
- Click the tab "Libraries".
- Click "Add Libraries", select "JRE System Library",
Next
- Select the bottom item: Workspace default JRE
(jdk1.x.x. etc....)
(Notice that it is now a JDK and not the JRE!)
- Click "Finish"
- Now remove the JRE libarary so you only have the JDK
library.
ex: JRE System Library [JavaSE-1.6]
- Click "OK"
- Now test clicking F3 on a java.lang or class from the JDK.
(Smile.....)
Miscellaneous
Topic |
Info |
Using Tomcat within
Eclipse |
http://www.coreservlets.com/Apache-Tomcat-Tutorial/eclipse.html |
Add a User Library |
Add a User Library
Create user libraries that you can reference
in your projects. The jar files can stay in one
location but when you publish or export they will be
packaged into your WAR file in the "WEB-INF\lib"
directory.
Window, Preferences, Java, Build Path, User
Libraries
You'll see a list of User Libraries.
Click "New"
User Library Name: struts2-jars
Click "Add JARs"
Navigate to the place you have your Struts2 jars.
Select the .jar files you want in that User Library!
Click "Open"
Click "OK"
|
Tasks View |
- Place //TODO <your comment> in your code to add
tasks that show up in the task view.
- Window->Show View->Tasks - this will show all
the TODO items. Double click on one and it will
open up the file and take you to that line.
|
Perspectives |
Perspective ICON is in the upper
right corner.
Open a perspective - Window, Open Perspective.
Save a perspective - Window, Save Perspective (ex: Java
<your initials)
Restore to prior saved perspective - Window, reset
perspective (misleading)
Ctrl-F8 - switch between perspectives. |
|
|