Why Does Eclipse Ask Me to Install Again and Again Mac
Eclipse for Java
How To Install Eclipse and Get Started with Java Programming
(on Windows, macOS and Ubuntu)
Eclipse (@ www.eclipse.org) is an open up-source Integrated Development Surround (IDE) supported by IBM. Eclipse is popular for Coffee application evolution (Java SE and Java EE) and Android apps. It also supports C/C++, PHP, Python, Perl, and other web project developments via extensible plug-ins. Eclipse is cross-platform and runs under Windows, Linux and macOS.
Eclipse Versions
The various versions are:
- Eclipse 1.0 (November 7, 2001): based on an before Java IDE called VisualAge from IBM.
- Eclipse 2.0 (June 28, 2002)
- Eclipse ii.1 (March 28, 2003)
- Eclipse 3.0 (June 25, 2004)
- Eclipse iii.one (June 28, 2005)
- Eclipse 3.2 (June 30, 2006) (Callisto - named afterwards one of the Jupiter's Galilean moons): started annual simultaneous release of all the related Eclipse projects.
- Eclipse 3.3 (June 25, 2007) (Europa - named after another Jupiter's Galilean moons)
- Eclipse 3.iv (June 19, 2008) (Ganymede - named afterwards yet another Jupiter'due south Galilean moons)
- Eclipse 3.5 (June 12, 2009) (Galileo - named after the peachy 17th century scientist and astronomer Galileo Galilei)
- Eclipse three.6 (June 23, 2010) (Helios - named afterwards god of the dominicus in Greek Mythology)
- Eclipse 3.seven (June 23, 2011) (Indigo)
- Eclipse 4.2 (June 27, 2012) (Juno)
- Eclipse four.iii (June 2013) (Kepler)
- Eclipse iv.4 (June 2014) (Luna)
- Eclipse 4.5 (June 2015) (Mars)
- Eclipse 4.6 (June 2016) (Neon)
- Eclipse 4.vii (June 2017) (Oxygen)
- Eclipse four.8 (June 2018) (Photon)
- Eclipse 2018-09 (4.9) (starting quarterly release), Eclipse 2018-12 (iv.x)
- Eclipse 2019-03 (4.eleven), Eclipse 2019-06 (4.12), Eclipse 2019-09 (4.13), Eclipse 2019-12 (iv.14)
- Eclipse 2020-03 (iv.15), Eclipse 2020-06 (4.16), Eclipse 2020-09 (4.17), Eclipse 2020-12 (4.18)
- Eclipse 2021-03 (4.19), Eclipse 2021-06 (iv.20), Eclipse 2010-09 (four.21), Eclipse 2021-12 (4.22)
- Eclipse 2022-03 (4.23)
How to Install Eclipse IDE 2021-12 for Coffee Developers
How to Install Eclipse on Windows
Footstep 0: Install JDK
To use Eclipse for Java programming, yous need to get-go install Java Development Kit (JDK). Read "How to Install JDK for Windows".
Step 1: Download
Download Eclipse from https://world wide web.eclipse.org/downloads/packages/. Choose "Eclipse IDE for Java Developers" and "Windows x86_64" (e.g., "eclipse-coffee-2021-12-R-win32-x86_64.zippo
" - about 313MB) ⇒ Download.
Footstep 2: Unzip
To install Eclipse, simply unzip the downloaded file into a directory of your choice (e.thou., "c:\myProject
").
I prefer the cipher version, because there is no need to run whatsoever installer. Moreover, you can only delete the unabridged Eclipse directory when it is no longer needed (without running whatsoever un-installer). You are free to move or rename the directory. Y'all can install (unzip) multiple copies of Eclipse in the aforementioned machine.
How to Install Eclipse on macOS
To utilize Eclipse for Java programming, you need to first install JDK. Read "How to install JDK for macOS".
To install Eclipse:
- Goto http://www.eclipse.org/downloads/package/. Choose "Eclipse IDE for Java Developers" and "macOS x86_64" (for Intel processor). Yous volition receive a DMG file (e.g., "
eclipse-java-2021-12-R-macosx-cocoa-x86_64.dmg
"). - Double-click the downloaded Disk Image (DMG) file. Follow the screen instructions to install Eclipse. Eclipse will exist installed nether "
/Applications/eclipse
". (To confirm!)
How to Install Eclipse on Ubuntu Linux
Eclipse comes with many flavors (See "Eclipse Packages" @ https://www.eclipse.org/downloads/compare.php):
- To use Eclipse for Java programming, choose "Eclipse IDE for Coffee Developers" (JavaSE) or "Eclipse IDE for Java EE Developers" (JavaEE). You need to first install JDK. Read "How to install JDK on Ubuntu".
- To use Eclipse for PHP programming, choose "Eclipse IDE for PHP Developers".
- To utilize Eclipse for C/C++ programming, choose "Eclipse IDE for C/C++ Developers".
Nevertheless, you lot tin can install any package, and so add together more features when needed.
To install Eclipse (e.one thousand, for Java Programming):
- Download Eclipse from http://www.eclipse.org/downloads/. Under "Get Eclipse IDE 2020-12" ⇒ Click the link "Download Packages" (instead of pushing the push "Download x86_64"). Choose "Eclipse IDE for Java Developers" for Java SE program development; or "Eclipse IDE for Java EE Developers" for developing webapps ⇒ Linux x86_64. You will receive a tarball (e.g., "
eclipse-java-2020-12-R-linux-gtk-x86_64.tar.gz
") in the "~/Downloads
" folder. - Nosotros shall install Eclipse under
/usr/local
.$ cd /usr/local $ sudo tar xzvf ~/Downloads/eclipse-java-2020-12-R-linux-gtk-x86_64.tar.gz $ cd /usr/bin $ sudo ln -s /usr/local/eclipse/eclipse $ ls -ld /usr/bin/eclipse lrwxrwxrwx 1 root root 26 Aug xxx eleven:53 /usr/bin/eclipse -> /usr/local/eclipse/eclipse $ which eclipse /usr/bin/eclipse
To run Eclipse, open the "/usr/local/eclipse
" folder and click on the "Eclipse" icon; or start a "Last", enter "eclipse".
Lock Eclipse on Launcher
Simply start Eclipse. Right-click the Eclipse icon ⇒ "Lock to Launcher" or "Add to Favourite".
(For older version - If the to a higher place don't work) Create a /usr/share/applications/eclipse.desktop
file with the following contents:
[Desktop Entry] Name=Eclipse Type=Application Exec=eclipse Terminal=false Icon=/usr/local/eclipse/icon.xpm Annotate=Integrated Development Environment NoDisplay=simulated Categories=Evolution;IDE; Name[en]=Eclipse
Starting time Eclipse, correct-click on the Eclipse icon on launcher ⇒ "Lock to launcher".
Writing your Commencement Java Programme in Eclipse
Step 0: Launch Eclipse
- Launch Eclipse by running "
eclipse.exe
" from the Eclipse installed directory. - Choose an appropriate directory for your workspace, i.e., where y'all would like to salve your files (due east.g.,
c:\myProject\eclipse
for Windows) ⇒ Launch. - If the "Welcome" screen shows up, close it by clicking the "close" button side by side to the "Welcome" title.
Step 1: Create a new Java Project
For each Java application, you need to create a project to continue all the source files, classes and relevant resource.
To create a new Java projection:
- Choose "File" carte ⇒ "New" ⇒ "Java projection" (or "File" ⇒ "New" ⇒ "Project" ⇒ "Java project").
- The "New Java Project" dialog pops upwards.
- In "Project name", enter "
FirstProject
". - Check "Use default location".
- In "JRE", select "Utilise an execution environs JRE (JavaSE-17). Make sure that your JDK is 11 and above.
- In "Project Layout", check "Use project folder as root for sources and class files".
- In "Module", UNCHECK "Create module-info.java" file.
- In "Project name", enter "
- IF "Create module-info.coffee" dialog appears, Click "Don't Create".
Step 2: Write a Hello-earth Java Plan
- In the "Package Explorer" (left pane) ⇒ Right-click on "
FirstProject
" (or use the "File" menu) ⇒ New ⇒ Class. - The "New Java Course" dialog pops upward.
- In "Source folder", keep the "FirstProject".
- In "Package", leave it EMPTY. Delete the content if it is not empty.
- In "Proper noun", enter "
Hello
". - Check "
public static void primary(String[] args)
". - Don't alter the rest.
- The source file "
Howdy.java
" opens on the editor panel (the center pane). Enter the following codes:public class Hello { public static void main(String[] args) { System.out.println("How-do-you-do, earth!"); } }
Step 3: Compile & Execute the Java Plan
- There is no need to compile the Coffee source file in Eclipse explicitly. Information technology is considering Eclipse performs the and then-called incremental compilation, i.east., the Coffee statement is compiled as and when information technology is entered.
- To run the program, right-click anywhere on the source file "
Hello.java
" (or choose "Run" card) ⇒ Run Every bit ⇒ Java Application. - The output "How-do-you-do, world!" appears on the Console panel (the bottom pane).
NOTES:
- You should create a NEW Java project for EACH of your Java application.
- Nevertheless, Eclipse allows you to go on more than one programs in a project, which is handy for writing toy programs (such as your tutorial exercises). To run a particular program, open and right-click on the source file ⇒ Run As ⇒ Java Application.
- Clicking the "Run" button (with a "Play" icon) runs the recently-run program (based on the previous configuration). Try clicking on the "down-arrow" likewise the "Run" button.
Correcting Syntax Errors
Eclipse performs incremented compilation, as and when a source "line" is entered. It marked a source line having syntax fault with a RED CROSS. Identify your cursor at the RED Cantankerous to view the error bulletin.
Y'all CANNOT RUN the program if there is whatsoever syntax error (marked by a Ruby Cross earlier the filename). Correct all the syntax errors; and RUN the plan.
HINTS: In some cases, Eclipse shows a Orangish Lite-Seedling (for HINTS) next to the Mistake Scarlet-Cross (Line v in the above diagram). You tin can click on the Calorie-free-BULB to get a list of HINTS to resolve this detail fault, which may or may not work!
SYNTAX WARNING: marked by a orangish triangular exclaimation sign. Different errors, warnings may or may not cause problems. Effort to set up these warnings besides. But you tin RUN your program with warnings.
Read the Eclipse Documentation
At a minimum, you SHOULD scan through Eclipse'due south "Workbench User Guide" and "Coffee Development User Guide" - accessible via the Eclipse'southward "Welcome" page or "Help" card. This volition save you many agonizing hours trying to figure out how to do somethings after.
Debugging Programs in Eclipse
Able to utilize a graphics debugger to debug program is crucial in programming. It could save you countless hours guessing on what went wrong.
Step 0: Write a Java Program
The following program computes and prints the factorial of n
(=i*2*iii*...*n
). The program, however, has a logical error and produce a incorrect respond for north
=20
("The Factorial of 20 is -2102132736
" - a negative number?!).
ane 2 3 4 5 6 7 8 9 10 11 12 xiii 14 15 16 | public grade Factorial { public static void principal(Cord[] args) { int n = 20; int factorial = 1; int i = 1; while (i <= due north) { factorial = factorial * i; i++; } Organization.out.println("The Factorial of " + n + " is " + factorial); } } |
Let'southward use the graphic debugger to debug the programme.
Step 1: Ready an Initial Breakpoint
A breakpoint suspends program execution for you lot to examine the internal states (due east.g., value of variables) of the program. Earlier starting the debugger, you need to set at least one breakpoint to suspend the execution inside the programme. Set a breakpoint at main()
method by double-clicking on the left-margin of the line containing chief()
. A blue circumvolve appears in the left-margin indicating a breakpoint is set at that line.
Step 2: Start Debugger
Right click anywhere on the source lawmaking (or from the "Run" menu) ⇒ "Debug As" ⇒ "Java Application" ⇒ choose "Aye" to switch into "Debug" perspective (A perspective is a particular arrangement of panels to suits a certain development chore such as editing or debugging). The plan begins execution merely suspends its functioning at the breakpoint, i.e., the main()
method.
As illustrated in the post-obit diagram, the highlighted line (likewise pointed to by a blueish arrow) indicates the argument to be executed in the side by side stride.
Step 3: Pace-Over and Picket the Variables and Outputs
Click the "Footstep Over" button (or select "Step Over" from "Run" menu) to single-footstep thru your program. At each of the step, examine the value of the variables (in the "Variable" panel) and the outputs produced by your program (in the "Console" Console), if any. Y'all can likewise place your cursor at whatsoever variable to inspect the content of the variable.
Single-stepping thru the program and watching the values of internal variables and the outputs produced is the ultimate mean in debugging programs - because it is exactly how the computer runs your programme!
Step 4: Breakpoint, Run-To-Line, Resume and Cease
As mentioned, a breakpoint suspends program execution and allow you lot examine the internal states of the program. To ready a breakpoint on a detail statement, double-click the left-margin of that line (or select "Toggle Breakpoint" from "Run" card).
"Resume" continues the programme execution, upward to the side by side breakpoint, or till the end of the programme.
"Single-step" thru a loop with a big count is time-consuming. Y'all could set up a breakpoint at the statement immediately exterior the loop (e.g., Line xi of the above programme), and issue "Resume" to complete the loop.
Alternatively, you can identify the cursor on a particular argument, and issue "Run-To-Line" from the "Run" menu to continue execution up to the line.
"Terminate" ends the debugging session. Always terminate your current debugging session using "Terminate" or "Resume" till the stop of the plan.
Step 5: Switching Back to Coffee perspective
Click the "Java" perspective icon on the upper-right corner to switch back to the "Java" perspective for further programming (or "Window" card ⇒ Open Perspective ⇒ Java).
Of import: I tin can'southward stress more that mastering the utilise of debugger is crucial in programming. Explore the features provided past the debuggers.
Other Debugger's Features
Step-Into and Pace-Return: To debug a method, you need to use "Stride-Into" to step into the first argument of the method. ("Step-Over" runs the function in a unmarried step without stepping through the statements within the function.) You could use "Step-Return" to return back to the caller, anywhere within the method. Alternatively, you could set up a breakpoint inside a method.
Alter the Value of a Variable: You lot can modify the value of a variable by entering a new value in the "Variable" console. This is handy for temporarily modifying the beliefs of a program, without changing the source code.
Tips & Tricks
General Usages (for all Programming Tasks)
These are the features that I notice to exist well-nigh useful in Eclipse:
- Maximizing Window (Double-Clicking): Yous can double-click on the "header" of any panel to maximize that particular panel, and double-click again to restore information technology back. This feature is especially useful for writing source code in full panel.
- Shorthand Templates (sysout, for,...): You tin can type "
sysout
" followed by a ctrl+infinite (or alt-/) every bit a shorthand for typing "Organization.out.println()
".
The default shortcut key (ctrl-space or alt-/) depends on the arrangement. Check your system'south shortcut key setting in "Edit" ⇒ "Content Help" ⇒ "Default". Have annotation that many of you employ ctrl+space to switch betwixt input languages. You lot demand to reconfigure either your language switching hot-cardinal or Eclipse.
Similarly, you can type "for" followed by ctrl-space (or alt-/) to become a for-loop.
Y'all can create your own autograph in "Window" menu ⇒ "Preferences" ⇒ "Java" ⇒ "Editor" ⇒ "Templates". (Alternatively, in "Window" ⇒ "Preferences" ⇒ type "template" as filter text and choose "Java" ⇒ "Editor" ⇒ "Templates".)
You tin alter your key settings in "Window" menu ⇒ "Preferences" ⇒ "General" ⇒ "Cardinal" ⇒ choose "Command", "Content Assist". (Alternatively, in "Window" ⇒ "Preferences" ⇒ type "key" as filter text and choose "Full general" ⇒ "Key".) - Intelli-Sense (ctrl-space): You can utilise ctrl-space to activate the "intelli-sense" (or content aid). That is, Eclipse volition offer yous the choices, while you are typing.
- Source Formatting (ctrl-shift-f): Correct-click on the source. Cull "Source" ⇒ "Format" to permit Eclipse to layout your source codes with the proper indentation.
- Source Toggle Comment (ctrl-/): To comment/uncomment a block of codes, choose "Source" ⇒ "Toggle Comment".
- Hints for Correcting Syntax Fault: If in that location is a syntax error on a statement, a ruddy marking will evidence up on the left-margin on that argument. You could click on the "light bulb" to brandish the fault message, and also select from the available hints for correcting that syntax error.
- Refactor (or Rename) (alt-shift-r): You can rename a variable, method, course, package or even the project easily in Eclipse. Select and right-click on the entity to be renamed ⇒ "Refactor" ⇒ "Rename". Eclipse can rename all the occurrences of the entity.
- Line Numbers: To prove the line numbers, choose "Window" carte du jour ⇒ "Preferences" ⇒ "General" ⇒ "Editors" ⇒ "Text Editors" ⇒ Check the "Show Line Numbers" Box. You lot can also configure many editor options, such as the number of spaces for tab. Alternatively, yous can right-click on the left-margin, and check "Evidence Line Numbers".
- Error Message Hyperlink: Click on an error message will hyperlink to the corresponding source statement.
- Changing Font Blazon and Size: From "Window" menu ⇒ "Preferences" ⇒ "General" ⇒ "Appearance" ⇒ "Colors and Fonts" ⇒ aggrandize "Coffee" ⇒ "Java Editor Text Font" ⇒ "Edit". (Alternatively, in "Window" ⇒ "Preferences" ⇒ type "font" as filter text and cull the advisable entry.)
- Unicode Support: To enable Unicode support, select "Window" bill of fare ⇒ Preferences ⇒ General ⇒ Workspace ⇒ Text file encoding ⇒ UTF-8. This sets the default character set used for file encoding, similar to VM'south command-line pick
-Dfile.encoding=UTF-8
. Commonly used charsets for Unicode are UTF-viii, UTF-16 (with BOM), UTF-16BE, UTF-16LE. Other charsets are US-ASCII, ISO-8859-1. - Mouse Hover-over: In debug fashion, you could configure to show the variable's value when the mouse hovers over the variable. Select "Window" card ⇒ "Preferences" ⇒ "Java" ⇒ "Editor" ⇒ "Hover".
- Comparing Ii Files: In "Package Explorer", select 2 files (hold the control key) ⇒Right-click ⇒ Compare with.
- Setting Keyboard Shortcut Keys: Y'all can set/alter the keyboard shortcut keys at "Window" ⇒ "Preferences" ⇒ "General" ⇒ "Cardinal".
I similar to set the ofttimes-used commands to Ctrl-ane to Ctrl-10, for examples, "Run Java Awarding" to "Ctrl-1", etc. - Useful Eclipse Shortcut Keys:
- F3: Goto the proclamation of the highlighted variable/method.
- Ctrl-Shift-Chiliad: Search for ALL references of the highlighted variable/method in workspace.
- Ctrl-G: Search for the Declaration of a variable/method in workspace.
Don't use Find (Ctrl-F), but utilise the above context-sensitive search. - Ctrl-Shift-F: Format the source code.
- Ctrl-Shift-O: Organize imports.
- Alt-Shift-R: Rename. (Don't use Detect/Replace.)
- Ctrl-Space: auto-complete.
- Package Explorer vs. Navigator: We usually use "Parcel Explorer" in programming, just it will not show you all the folders and files nether the project. On the other mitt, "Navigator" is a file director that shows the exact file structure of the project (similar to Windows Explorer). You tin can enable the Navigator by "Window" ⇒ Show view ⇒ Navigator.
- Spell Check: To enable spell cheque, select Window ⇒ Preferences ⇒ blazon "spell" in the filter ⇒ General ⇒ Editors ⇒ Text Editors ⇒ Spelling ⇒ Cheque "Enable spell checking". Besides provide a "User defined lexicon" (with an initially empty text file).
To correct mis-spell words, right-click and press ctrl-one (or Edit menu ⇒ Quick Gear up). - Eclipse's Log File: Goto Assistance ⇒ nearly Eclipse ⇒ Installation details ⇒ Configuration ⇒ View Mistake Log.
- Viewing two files in dissever screen: Just click and hold on the championship of one file and drag it to the lower side of the screen. [To view the aforementioned file on split screen, create a new editor window by selecting Window ⇒ New Editor; and drag i window to the lower side of the screen.]
- Block Select (Cavalcade Select): Button Alt-Shift-A to toggle between block-select mode and normal style.
- Snippets:
- To view the snippet window: choose "Window" ⇒ Prove View ⇒ Snippets.
- To create a new snippet category: Right-click ⇒ Customize ⇒ New.
- To create a new snippet item: Re-create the desired text ⇒ Select the snippet category ⇒ paste as snippet.
- To insert a snippet: place the cursor on the desired location at the editor panel ⇒ click the snippet detail.
- Word Wrap (Line Wrap): Word-wrap (or line-wrap) is essential for editing long HTML documents without the horizontal scroll bar. However, the Eclipse'south HTML Editor and Text Editor exercise not support word-wrap.
You could install a plug-in called "Give-and-take Wrap" from http://ahtik.com/eclipse-update/.
Cull "Assistance" ⇒ Install New Software ⇒ in "Work with" Enter "http://ahtik.com/eclipse-update/".
To actuate word wrap, right-click on the editor panel ⇒ select "Word Wrap". - Creating "link binder" in projection: Yous do not have to identify all the folders nether the project base directory, instead, you can apply and then-called "link folders" to link to binder outside the project base directory.
To create a link folder in a project, correct-click on the projection ⇒ File ⇒ New ⇒ Folder ⇒ Advanced ⇒ Check Link to alternate Location (Linked Folder). - Running Eclipse in "clean" style: Yous can run eclipse in and so-called "
clean
" style, which wipes all the buried data and re-initialize the cache, by running eclipse from command-line with "-clean" statement (i.e., "eclipse -make clean
"). Information technology is useful if something is not working proper, particularly if y'all install a new copy of Eclipse. - Show the Right Margin: Window ⇒ Preferences ⇒ General ⇒ Editors ⇒ Text Editors ⇒ Show Print Margin and ready the cavalcade number.
- Permit me know if you have more tips to be included here.
Update Eclipse and Install new Software
- Install New Software: Select "Assist" menu ⇒ Install New Software ⇒ In "Work With", pull down the select menu and choose a software site.
- Update: Select "Help" carte ⇒ Cheque for Updates ⇒.
For Coffee Application Evolution Only
- Pocket-size Toy Java Programs: You can go on many small programs (with
main()
) in one Java project instead of create a new project for each toy plan. To run the desired program, correct-click on the source file ⇒ "Run every bit" ⇒ "Java Application". - Scanner/printf() and JDK 1.5: If yous encounter syntax error in using
printf()
orScanner
(which are available from JDK 1.5), you need to check your compiler settings. Select "Window" menu ⇒ Preferences ⇒ open the "Java" node ⇒ select "Compiler" ⇒ in "Compiler compliance level" ⇒ select the latest release, which should be "1.5" or to a higher place. - Command-Line Arguments: To provide command-line arguments to your Java program in Eclipse, right-click on the source file ⇒ "Run Configurations" ⇒ Under the "Chief" panel, check that "Project" name and "Main Class" are appropriate ⇒ Select the "Statement" tab ⇒ type your command-line arguments inside the "Program Arguments" box ⇒ "Run".
- Resolving Import (Ctrl-Shift-o): To enquire Eclipse to insert the
import
statements for classes. Useful when you copy a large chunk of codes without the corresponding import statements. - Including Another Projection: To include another project in the aforementioned work space, correct-click on the projection ⇒ Build Path ⇒ Configure Build Path... ⇒ Select "Projects" tab ⇒ "Add..." to select projection in the existing work infinite ⇒ OK.
- Exporting a Project to a JAR file: Right-click on the project ⇒ Consign... ⇒ Java, JAR File ⇒ Next ⇒ Select the files to exist exported ⇒ Next ⇒ Next ⇒ In "JAR Manifest Specification" dialog, enter the main class (if you wish to run the JAR file direct) ⇒ Finish.
- Unit of measurement Testing: If you go along your test in another project, you need to include the project under exam in your Build Path (see to a higher place).
To create a test example: Right-click on the projection ⇒ New ⇒ JUnit Examination Case ⇒ the "New JUnit Test Case" dialog appears. Select "New JUnit 4 Test". In "Proper noun", enter your course proper name. In "Class under test", scan and select the class to be tested.
To run the test: Right-click ⇒ "Run Equally" ⇒ "JUnit Exam". The results are displayed in a special "JUnit panel". - Adding External JAR files & Native Libraries (".dll", ".lib", ".a", ".so"): Many external Java packages (such as JOGL, Java3D, JAMA, etc) are bachelor to extend the functions of JDK. These packages typically provide a "
lib
" directory containing JAR files (".jar
") (Coffee Annal - a single-file parcel of Java classes) and native libraries (".dll
", ".lib
" for windows, ".a
", ".so
" for Linux and macOS).
To include these external packages into an Eclipse'southward project, correct-click on the project ⇒ Build Path ⇒ Add External Athenaeum ⇒ Navigate to select the JAR files (".jar
") to be included.
In "Package Explorer", correct-click on the JAR file added ⇒ Properties:- To include native libraries ("
.dll
", ".lib
", ".a
", ".and then
"), select "Native Library" ⇒ "Location Path" ⇒ "External Folder". - To include the javadoc, select "JavaDoc Location" ⇒ "JavaDoc URL" ⇒ You can specify a local file or a remote link.
- To include source file (for debugging), select "Coffee Source Attachment".
Notes: The JAR files must be included in theCLASSPATH
. The native library directories must be included in JRE'southward property "java.library.path
", which normally but non necessarily includes all the paths from thePATH
surround variable. Read "External JAR files and Native Libraries". - To include native libraries ("
- Creating a User Library: You lot can also create a Eclipse's user library to include a gear up of JAR files and native libraries, that tin then exist added into subsequent Eclipse projects.
For example, I created a user library for "JOGL" as follows:
- From "Window" card ⇒ Preferences ⇒ Java ⇒ Build Path ⇒ User Libraries ⇒ New ⇒ In "User library name", enter "
jogl
". The "User Library" dialog appears. - In "User Library" dialog ⇒ Select "
jogl
" ⇒ Add JAR... ⇒ Navigate to<JOGL_HOME>/lib
, and select "gluegen-rt.jar
" and "jogl.jar
". - Expand the "
jogl.jar
" node ⇒ Select "Native library location: (none)" ⇒ Edit... ⇒ External Folder... ⇒ select<JOGL_HOME>/lib
. - Aggrandize the "
jogl.jar
" node ⇒ Select "Javadoc location: (none)"
⇒ Edit... ⇒ Javadoc in archive ⇒ In "Annal Path", "Scan" and select the downloaded JOGL API documentation zip-file ⇒ In "Path inside archive", "Browse" and expand the nothing-file to select the top-level path (if any) ⇒ Validate. Alternatively, you tin provide the path to the un-zipped javadocs. This is needed for Eclipse to brandish javadoc information virtually classes, fields, and methods. - You lot may provide the source files by editing "Source attachment: (none)". Source is needed simply if you are interested to debug into the JOGL source codes.
jogl
". - From "Window" card ⇒ Preferences ⇒ Java ⇒ Build Path ⇒ User Libraries ⇒ New ⇒ In "User library name", enter "
- Running an External Plan: Suppose that you desire to run a Perl script on the selected file, you lot tin configure an external tool as follows:
- From "Run" card ⇒ External Tools ⇒ External Tools Configuration... ⇒ The "External Tools Configuration" dialog appears.
- In "Name", enter your tool proper name.
- Cull the "Primary" tab ⇒ In "Location", "Scan File System..." to choose the perl interpreter "perl" ⇒ In "Arguments", enter "
path/scriptname.pl ${resource_loc}
", where${resource_loc}
is an Eclipse variable that denotes the currently selected resources with accented path. - Choose the "Common" tab ⇒ In "Standard Input and Output", uncheck "Allocate Console", cheque "File" and provide an output file (e.thousand.,
d:\temp\${resource_name}.txt
). - (If you use the CYGWIN perl interpreter, need to set surround variable CYGWIN=nodosfilewarning to disable alarm bulletin.)
- Viewing Hex Code of Primitive Variables in Debug mode: In debug perspective, "Variable" console ⇒ Select the "menu" (inverted triangle) ⇒ Coffee ⇒ Java Preferences... ⇒ Primitive Display Options ⇒ Cheque "Brandish hexadecimal values (byte, brusque, char, int, long)".
- Adding a New Version of JDK/JRE: First, you tin can bank check the installed JDK/JRE via "Window" menu ⇒ "Preferences" ⇒ Expand "Java" node ⇒ "Installed JREs". Check the "Location" current JRE installed to make certain that it is the intended one. You tin can utilize the "Add" button to add together a new version of JRE. For program evolution, I recommend that you add the JDK (instead of JRE). [The "Location" decides the extension directory used for including additional JAR files, e.thousand.,
$JAVA_HOME\jre\lib\ext
.]
For Web Developers
- HTML Editor: Apply the "Spider web Page Editor" (available in Eclipse Java EE), which provides the pattern view (WYSISYG).
To use the "Web Folio Editor", correct-click on the HTML file, open up as "Web Page Editor".
To make the "Spider web Page Editor" as default for HTML file, goto Window ⇒ Preferenes ⇒ Full general ⇒ Editor ⇒ File Associations ⇒ .htm and .html ⇒ Select "Spider web folio editor" ⇒ default.
File I/O in Eclipse
Suppose that your want to write a Java plan, which inputs from a text file called "xxxx.in
" and outputs to a text file called "xxxx.out
". This is a little tricky under Eclipse due to:
- When you lot create a text file in Windows' Notepad and saved information technology as "
xxxx.in
", Notepad volition append the ".txt
" to your file and it becomes "xxxx.in.txt
". Worse notwithstanding, the Windows' Explorer, by default, will not show the ".txt
" extension. (The first affair I always do to an alien computer is to change this setting. From "Tools" menu ⇒ Folder Options... ⇒ View ⇒ Uncheck "Hibernate extensions for known file types".) You need to put a pair of double quotes effectuallyxxxx.in
to override the default ".txt
" extension. This is one good reason not to apply Notepad for programming at all. Yous should use Eclipse to create the text file instead. - Which directory to go along the input file "
xxxx.in
" in Eclipse?- If you lot did not divide the sources and class files into two separate directories, so the answer is direct forrard, because at that place is simply one directory to place your input file.
- If you lot cull to keep your sources and class files in two dissever directories, eclipse will create ii sub-directories "src" and "bin" under the base of operations directory. Merely you need to put your input file "
xxxx.in
" in the base directory of your project, instead of the "src" or "bin"..
For writing elementary programs:
- Put the sources, class files, and the input/output files in the same directory. (When you create a new projection, select "Use projection binder equally root for sources and grade files" in "Project Layout".) (Merely put your sources and class files in separate directories for big project.)
- Y'all can create you input file from eclipse directly via "File" bill of fare ⇒ "New" ⇒ "File".
- Remember to add together a newline to the end of your input file.
- You may need to correct-click the projection and select "Refresh" to run across the output file "
xxxx.out
" created in the bundle explorer. - To open the "
xxxx.in
" and "xxxx.out
": correct-click ⇒ Open up With ⇒ Text Editor.
This is a sample JDK one.five program for file input/output:
import java.util.Scanner; import java.util.Formatter; import java.io.File; import java.io.IOException; public form FileIOTest { public static void main (Cord [] args) throws IOException { Scanner in = new Scanner(new File("FileIOTest.in")); Formatter out = new Formatter(new File("FileIOTest.out")); int a = in.nextInt(); int b = in.nextInt(); out.format("%d\north",a+b); out.close(); } }
Create the input text file called "FileIOTest.in
" with the post-obit contents and terminated with a newline:
55 66
Writing Swing Applications using Eclipse GUI Architect
Eclipse provides a visual GUI builder called "WindowBuilder" (@ https://www.eclipse.org/windowbuilder), which supports AWT/Swing, SWT (Eclipse's Standard Widget Toolkit - an alternative to JDK's AWT/Swing), XWT, GWT, eRCT.
Pace 0: Install WindowBuilder
To install "WindowBuilder", goto "Help" ⇒ Install New Software ⇒ In "Work with", enter "https://download.eclipse.org/windowbuilder/latest/" (Y'all tin can find the proper link from "http://www.eclipse.org/windowbuilder/download.php") ⇒ Check "WindowBuilder" ⇒ Next ⇒ Next ⇒ Accept the licence ⇒ Finish.
Step 1: Create a New "Java Application" Project
- Choose "File" menu ⇒ "New" ⇒ "Java projection".
- The "New Java Project" dialog pops up.
- In the "Projection name" field, enter "
FirstSwingProject
". - Check "Apply default location".
- In the "JRE" box, select "Use default JRE (currently 'JDK1.x')".
- Click "End".
- In the "Projection name" field, enter "
Step 2: Create a Swing JFrame Subclass
- Choose "File" carte ⇒ "New" ⇒ "Others" ⇒ "WindowBuilder" ⇒ "Swing Designer" ⇒ "JFrame" ⇒ "Adjacent".
- In the "Create JFrame" dialog ⇒ Enter "SwingMain" in the "Name" field ⇒ "Finish".
- Select the "Design" pane.
- In "Layouts", select "FlowLayout" and click on the "design course".
- From "Components", select "
JLabel
" and click on the blueprint form. Change the label text to "Counter: ". Select a "JTextField" and place it on the design form. Change the text to "0". Select a "JButton" and identify information technology on the design form. Change the text label to "Count". - To attach a event-handler to the button, double-click the
JButton
to switch into the "Source" pane, with the event-handler skeleton created. Consummate theactionPerformed()
as follows:public void actionPerformed(ActionEvent eastward) { count++; textField.setText(count + ""); }
Add an instance variable calledcount
equally follow:public course SwingMain extends JFrame { private int count = 0; ......
- Y'all can at present ready run the plan. Right-click on the project ⇒ Run As ⇒ Java Application.
Eclipse Generated Codes
Written report the codes generated by Eclipse GUI Architect, as follows, which is just a typical Swing application.
1 2 3 iv 5 6 7 8 9 ten 11 12 13 fourteen 15 16 17 18 19 xx 21 22 23 24 25 26 27 28 29 thirty 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import java.awt.*; import java.awt.result.*; import javax.swing.*; import javax.swing.border.EmptyBorder; public class SwingMain extends JFrame { private JPanel contentPane; private JTextField textField; private int count = 0; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { SwingMain frame = new SwingMain(); frame.setVisible(true); } catch (Exception east) { e.printStackTrace(); } } }); } public SwingMain() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, v, 5)); setContentPane(contentPane); contentPane.setLayout(new FlowLayout(FlowLayout.Centre, five, five)); JLabel lblNewLabel = new JLabel("Counter: "); contentPane.add(lblNewLabel); textField = new JTextField(); textField.setText("0"); contentPane.add(textField); textField.setColumns(ten); JButton btnCount = new JButton("Count"); btnCount.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { count++; textField.setText(count + ""); } }); contentPane.add(btnCount); } } |
Eclipse for C/C++ Programming
Here.
Eclipse PDT (PHP Development Tool)
Hither.
Eclipse-JavaEE and Database Development
Reference: "Data Tools Platform User Documentation" @ Eclipse Welcome page.
Y'all need to install:
- "Eclipse for Java EE" (aka "Eclipse IDE for Enterprise Coffee Developers").
- "MySQL Community Server" and "MySQL Connector/J Driver". Read "How to install and get started with MySQL".
To use Eclipse for MySQL development:
- Switch to "Database Development" perspective:
From "Window" carte du jour ⇒ Open up Perspective ⇒ Other ⇒ Database Development. - Create a Database Connection: Start your MySQL database server ⇒ Right-click "Database Connection" ⇒ New. Take note that each database connection connect to ONE particular database in the database server with a URL in the form of jdbc:mysql://localhost:3306/database-name.
- In "Connection Contour", choose "MySQL" ⇒ Next.
- In "Drivers", click the icon for "New Commuter Definition" (if the driver has not been defined).
- In "Specify a Commuter Template and Definition Name":
- Choose the "Name/Blazon" tab ⇒ Choose one of the database driver as our template (eastward.g. MySQL 5.i) for farther customization ⇒ Set your "Commuter proper noun", e.g., "mysql-connector-java-8.0.23".
- Switch to "JAR List" tab ⇒ Clear All ⇒ Click "Add JAR/Zip" and select the driver JAR file, east.k., mysql-connector-java-eight.0.23.jar.
- Switch to "Properties" tab ⇒ Cheque the parameters.
- OK.
- Enter the "Database" proper noun, URL (with the same database proper noun), and the "Password" ⇒ Click "Test Connexion"
- Stop.
- In "Datasource Explorer", yous can "connect" and "disconnect" the connection.
- To view and edit table visually, expand database "Schemas" to look for the table. Right-right on the table ⇒ Data ⇒ Edit. You can modify the cells and "save" the changes.
- To create a new SQL script, cull File ⇒ New ⇒ SQL File ⇒ You may use an existing projection or create a new project (General|Project or Web|Dynamic Web Project) ⇒ Enter filename, and set the connection profile name ⇒ Cease. Enter a SQL statement (e.g., SELECT * FROM tablename) ⇒ Right-click on the text ⇒ "Execute Current Text" or "Execute All".
- To use an existing SQL file, driblet the file into a projection and open the SQL file. In Connection profile, set the type and connection name. Right-click on a statement ⇒ "Execute ...".
Developing and Deploying Webapps in Eclipse-JavaEE
Setting Upward Eclipse-JavaEE for Web Development
- Install "Eclipse for Java EE" (aka "Eclipse IDE for Enterprise Java Developers").
- Install Tomcat (or Glassfish) server.
- Configuring Web Server: Launch Eclipse ⇒ Window ⇒ Preferences ⇒ Expand the "Server" node ⇒ "Runtime Environments" ⇒ "Add..." ⇒ Aggrandize "Apache" and select "Apache Tomcat vX.X" ⇒ Enter your "Tomcat Installation Directory" ⇒ "Finish".
Writing a Hullo-world Servlet
- Switch to "Java EE" perspective (which is the default perspective for Eclispe-JavaEE):
From "Window" carte ⇒ Open Perspective ⇒ Other ⇒ Java EE. - Create a new Web Awarding Projection: from "File" ⇒ New ⇒ Dynamic Web Project (under "Spider web" category) ⇒ In "Project Proper noun", enter "
HelloServletProject
" ⇒ "Stop". - Create a new Servlet: Right-click on the project "
HelloServletProject
" ⇒ New ⇒ Servlet ⇒ In "Java Packet", enter "mypkg
"; in "Form Proper noun", enter "HelloServlet
" ⇒ Next ⇒ In "URL Mappings", select "/HelloServlet
" ⇒ "Edit" to "/sayhello
" ⇒ Adjacent ⇒ In "Which method stubs would you like to create", check "Inherited abstruse method", "doGet" and "doPost" (default) ⇒ Finish.
In "HelloServlet.java", enter the following codes:package mypkg; import coffee.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/sayhello") public form HelloServlet extends HttpServlet { private static final long serialVersionUID = 1L; public HelloServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head><title>Hello Servlet</title></head>"); out.println("<torso>"); out.println("<h1>Hullo World, from Servlet!</h1>"); out.println("<p>Method: " + request.getMethod() + "</p>"); out.println("<p>Request URI: " + request.getRequestURI() + "</p>"); out.println("<p>Protocol: " + request.getProtocol() + "</p>"); out.println("<p>PathInfo: " + asking.getPathInfo() + "</p>"); out.println("<p>Remote Address: " + request.getRemoteAddr() + "</p>"); out.println("<p>Generate a Random Number per asking: <strong>" + Math.random() + "</stiff></p>"); out.println("</body>"); out.println("</html>"); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
(For Servlet two.4/2.5 with Tomcat 6) The notation
@WebServlet
is new in Servlet 3.0 and is not supported in Servlet 2.4/ii.5. Hence, you need to manually configure the URL for the servlet in the Web Application Deployment Descriptor "spider web.xml
" under directory "WEB-INF
", as follows:<?xml version="i.0" encoding="ISO-8859-ane"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://coffee.dominicus.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/spider web-app_3_0.xsd" version="3.0" metadata-complete="truthful"> <servlet> <servlet-name>HelloServletExample</servlet-name> <servlet-class>mypkg.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloServletExample</servlet-name> <url-pattern>/sayhello</url-pattern> </servlet-mapping> </web-app>
- To execute the Servlet, right-click on the "
HelloServletProject
" ⇒ "Run As" ⇒ "Run on Server" ⇒ Modify the URL to "http://localhost:8080/HelloServletProject/sayhello
".
Writing a Hello-world JSP (Java Server Pages)
- Create a new Spider web Awarding: File ⇒ New ⇒ Dynamic Web Project (nether "Web" category) ⇒ In "Projection Name", enter "
HelloJSPProject
" ⇒ Finish. - Create a new JSP File: Correct-click on the project "
HelloJSPProject
" ⇒ New ⇒ JSP File ⇒ The parent binder shall be "HelloJSPProject/WebContent" ⇒ In "File Name", enter "hello.jsp
" ⇒ "Finish". - Enter the following HTML/JSP codes:
<%@ page language="java" contentType="text/html; charset=ISO-8859-ane" pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <caput> <meta charset="ISO-8859-i"> <title>Hullo JSP</title> </head> <torso> <h1>Hi World, from JSP</h1> <p>Method: <%= request.getMethod() %></p> <p>Asking URI: <%= request.getRequestURI() %></p> <p>Protocol: <%= request.getProtocol() %></p> <p>PathInfo: <%= request.getPathInfo() %></p> <p>Remote Address: <%= request.getRemoteAddr() %></p> <% double num = Math.random(); if (num > 0.75) { %> <h2>You'll have a lucky twenty-four hour period!</h2><p>(<%= num %>)</p> <% } else { %> <h2>Well, life goes on ... </h2><p>(<%= num %>)</p> <% } %> <h3><a href="<%= request.getRequestURI() %>">Try Once again</a></h3> </trunk> </html>
- To execute the JSP, right-click on "
hello.jsp
" ⇒ Run Every bit ⇒ Run on Server.
Exporting a Webapp as a WAR file
Right-click on the projection to be exported ⇒ Export ⇒ State of war File ⇒ In "Destination", specify the destination directory and filename (the filename shall be the web application name) ⇒ Finish.
- To deploy the war file in Tomcat, simply drop the war file into Tomcat'southward "
webapps
" folder. The war file volition exist automatically extracted and deployed. The web application name is the state of war-filename. - You could utilize WinZip (or WinRAR) to view the content of the war file, as war-file is in Naught format.
Deploying a webapp outside the Tomcat'southward webapps directory
To deploy a webapp (called howdy
) outside the %TOMCAT_HOME%\webapps
directory, create a hello.xml
file every bit follows and place it nether the %TOMCAT_HOME%\conf\Catalina\localhost
:
<Context displayName="hello" docBase="C:\path\to\webapp" path="/hello" reloadable="true" />
Writing a Howdy-earth JSF (JavaServer Faces)
[TODO]
Debugging Webapps
You can debug a webapp but similar standalone application. For example, y'all tin can gear up breakpoints, single-step through the programs, etc.
REFERENCES & RESOURCES
- Eclipse female parent site @ https://world wide web.eclipse.org.
- Eclipse documentation and user guides, accessible via Eclipse's Aid and menu.
Latest version tested: Eclipse Java and Eclipse JavaEE 2021-12
Concluding modified: Jan 2022
Source: https://www3.ntu.edu.sg/home/ehchua/programming/howto/eclipsejava_howto.html
0 Response to "Why Does Eclipse Ask Me to Install Again and Again Mac"
Post a Comment