Eclipse How to Run Program Again With Arguments

Eclipse for Java

How To Install Eclipse and Get Started with Coffee Programming
(on Windows, macOS and Ubuntu)

Eclipse (@ www.eclipse.org) is an open-source Integrated Development Environment (IDE) supported past IBM. Eclipse is popular for Java application development (Java SE and Java EE) and Android apps. Information technology 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 ane.0 (Nov vii, 2001): based on an earlier 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 3.1 (June 28, 2005)
  • Eclipse 3.2 (June 30, 2006) (Callisto - named afterward one of the Jupiter'southward Galilean moons): started almanac simultaneous release of all the related Eclipse projects.
  • Eclipse 3.3 (June 25, 2007) (Europa - named later on another Jupiter's Galilean moons)
  • Eclipse iii.4 (June 19, 2008) (Ganymede - named afterwards yet another Jupiter'southward Galilean moons)
  • Eclipse 3.five (June 12, 2009) (Galileo - named subsequently the corking 17th century scientist and astronomer Galileo Galilei)
  • Eclipse 3.half-dozen (June 23, 2010) (Helios - named after god of the sun in Greek Mythology)
  • Eclipse 3.7 (June 23, 2011) (Indigo)
  • Eclipse iv.2 (June 27, 2012) (Juno)
  • Eclipse 4.3 (June 2013) (Kepler)
  • Eclipse 4.4 (June 2014) (Luna)
  • Eclipse 4.5 (June 2015) (Mars)
  • Eclipse 4.half dozen (June 2016) (Neon)
  • Eclipse iv.7 (June 2017) (Oxygen)
  • Eclipse iv.8 (June 2018) (Photon)
  • Eclipse 2018-09 (4.9) (starting quarterly release), Eclipse 2018-12 (4.10)
  • Eclipse 2019-03 (4.xi), Eclipse 2019-06 (4.12), Eclipse 2019-09 (iv.13), Eclipse 2019-12 (4.fourteen)
  • 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.twenty), Eclipse 2010-09 (iv.21), Eclipse 2021-12 (4.22)
  • Eclipse 2022-03 (4.23)

How to Install Eclipse IDE 2021-12 for Java Developers

How to Install Eclipse on Windows

Step 0: Install JDK

To use Eclipse for Java programming, y'all need to beginning install Coffee Development Kit (JDK). Read "How to Install JDK for Windows".

Step 1: Download

Download Eclipse from https://www.eclipse.org/downloads/packages/. Choose "Eclipse IDE for Coffee Developers" and "Windows x86_64" (e.g., "eclipse-coffee-2021-12-R-win32-x86_64.zip" - about 313MB) ⇒ Download.

Step 2: Unzip

To install Eclipse, but unzip the downloaded file into a directory of your choice (east.g., "c:\myProject").

I adopt the null version, considering in that location is no need to run any installer. Moreover, you can just delete the unabridged Eclipse directory when it is no longer needed (without running any un-installer). You are gratis to motion or rename the directory. You tin install (unzip) multiple copies of Eclipse in the same machine.

How to Install Eclipse on macOS

To use Eclipse for Java programming, y'all need to first install JDK. Read "How to install JDK for macOS".

To install Eclipse:

  1. Goto http://www.eclipse.org/downloads/package/. Cull "Eclipse IDE for Java Developers" and "macOS x86_64" (for Intel processor). You lot volition receive a DMG file (east.1000., "eclipse-java-2021-12-R-macosx-cocoa-x86_64.dmg").
  2. Double-click the downloaded Disk Paradigm (DMG) file. Follow the screen instructions to install Eclipse. Eclipse will be 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 Coffee programming, choose "Eclipse IDE for Java Developers" (JavaSE) or "Eclipse IDE for Java EE Developers" (JavaEE). Yous 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 apply Eclipse for C/C++ programming, choose "Eclipse IDE for C/C++ Developers".

Nonetheless, you can install whatever bundle, and then add together more features when needed.

To install Eclipse (e.g, for Java Programming):

  1. Download Eclipse from http://www.eclipse.org/downloads/. Nether "Get Eclipse IDE 2020-12" ⇒ Click the link "Download Packages" (instead of pushing the push button "Download x86_64"). Cull "Eclipse IDE for Java Developers" for Java SE program development; or "Eclipse IDE for Coffee EE Developers" for developing webapps ⇒ Linux x86_64. You volition receive a tarball (eastward.g., "eclipse-java-2020-12-R-linux-gtk-x86_64.tar.gz") in the "~/Downloads" folder.
  2. Nosotros shall install Eclipse under /usr/local.
                    $              cd /usr/local              $              sudo tar xzvf ~/Downloads/eclipse-coffee-2020-12-R-linux-gtk-x86_64.tar.gz                  $              cd /usr/bin              $              sudo ln -south /usr/local/eclipse/eclipse               $              ls -ld /usr/bin/eclipse              lrwxrwxrwx 1 root root 26 Aug 30 11: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 "Terminal", enter "eclipse".

Lock Eclipse on Launcher

Simply start Eclipse. Correct-click the Eclipse icon ⇒ "Lock to Launcher" or "Add to Favourite".

(For older version - If the above don't work) Create a /usr/share/applications/eclipse.desktop file with the following contents:

[Desktop Entry] Name=Eclipse  Type=Application Exec=eclipse Terminal=imitation Icon=/usr/local/eclipse/icon.xpm Comment=Integrated Evolution Environment NoDisplay=false Categories=Evolution;IDE; Name[en]=Eclipse

Start Eclipse, right-click on the Eclipse icon on launcher ⇒ "Lock to launcher".

Writing your First Java Program in Eclipse

Step 0: Launch Eclipse
  1. Launch Eclipse past running "eclipse.exe" from the Eclipse installed directory.
  2. Cull an advisable directory for your workspace, i.e., where you would similar to relieve your files (e.g., c:\myProject\eclipse for Windows) ⇒ Launch.
  3. If the "Welcome" screen shows up, close it by clicking the "close" button adjacent to the "Welcome" title.
Stride ane: Create a new Java Project

For each Java awarding, you lot demand to create a project to proceed all the source files, classes and relevant resource.

To create a new Java project:

  1. Cull "File" card ⇒ "New" ⇒ "Java project" (or "File" ⇒ "New" ⇒ "Project" ⇒ "Coffee project").
  2. The "New Java Project" dialog pops upwards.
    1. In "Project proper noun", enter "FirstProject".
    2. Bank check "Apply default location".
    3. In "JRE", select "Use an execution environment JRE (JavaSE-17). Make sure that your JDK is xi and above.
    4. In "Project Layout", check "Use project folder as root for sources and course files".
    5. In "Module", UNCHECK "Create module-info.java" file.
    Push "Finish" button.
  3. IF "Create module-info.java" dialog appears, Click "Don't Create".
Step 2: Write a Hello-world Java Program
  1. In the "Package Explorer" (left pane) ⇒ Correct-click on "FirstProject" (or utilize the "File" carte) ⇒ New ⇒ Class.
  2. The "New Coffee Class" dialog pops up.
    1. In "Source folder", keep the "FirstProject".
    2. In "Package", get out information technology EMPTY. Delete the content if it is not empty.
    3. In "Proper noun", enter "Hello".
    4. Cheque "public static void main(Cord[] args)".
    5. Don't change the rest.
    Button "Finish" button.
  3. The source file "Hello.java" opens on the editor panel (the centre pane). Enter the post-obit codes:
    public class Hello {    public static void main(String[] args) {              Organization.out.println("How-do-you-do, earth!");              } }
Step 3: Compile & Execute the Coffee Plan
  1. There is no need to compile the Java source file in Eclipse explicitly. It is considering Eclipse performs the and so-called incremental compilation, i.e., the Java argument is compiled every bit and when it is entered.
  2. To run the program, right-click anywhere on the source file "Hello.coffee" (or choose "Run" bill of fare) ⇒ Run As ⇒ Coffee Awarding.
  3. The output "Hello, globe!" appears on the Console panel (the bottom pane).
NOTES:
  • You lot should create a NEW Java project for EACH of your Java application.
  • Withal, Eclipse allows you to continue more than ane 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 Every bit ⇒ Java Application.
  • Clicking the "Run" button (with a "Play" icon) runs the recently-run plan (based on the previous configuration). Effort clicking on the "downwards-arrow" as well 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 error with a Cherry-red Cross. Place your cursor at the Scarlet CROSS to view the error bulletin.

You CANNOT RUN the plan if there is any syntax error (marked by a RED CROSS before the filename). Correct all the syntax errors; and RUN the programme.

EclipseJavaSyntaxError.png

HINTS: In some cases, Eclipse shows a ORANGE LIGHT-Bulb (for HINTS) adjacent to the ERROR RED-CROSS (Line 5 in the above diagram). You can click on the LIGHT-Seedling to get a list of HINTS to resolve this particular mistake, which may or may not work!

SYNTAX Alarm: marked by a orange triangular exclaimation sign. Unlike errors, warnings may or may not cause issues. Try to fix these warnings as well. But you lot can RUN your program with warnings.

Read the Eclipse Documentation

At a minimum, you SHOULD browse through Eclipse's "Workbench User Guide" and "Java Development User Guide" - accessible via the Eclipse'southward "Welcome" folio or "Assist" menu. This will save you many agonizing hours trying to figure out how to do somethings later.

Debugging Programs in Eclipse

Able to utilise a graphics debugger to debug program is crucial in programming. It could salvage you lot countless hours guessing on what went wrong.

Step 0: Write a Java Program

The following program computes and prints the factorial of northward (=1*ii*3*...*n ). The programme, even so, has a logical error and produce a wrong answer for northward =20 ("The Factorial of 20 is -2102132736" - a negative number?!).

1 2 three 4 v vi 7 8 9 10 11 12 13 14 15 16
                    public class Factorial {    public static void main(Cord[] args) {       int n = 20;                 int factorial = 1;            int i = ane;       while (i <= north) {          factorial = factorial * i;          i++;       }       System.out.println("The Factorial of " + n + " is " + factorial);    } }

Permit'due south use the graphic debugger to debug the program.

Stride 1: Set an Initial Breakpoint

EclipseJavaDebugSetBreakpoint.png

A breakpoint suspends plan execution for y'all to examine the internal states (eastward.yard., value of variables) of the program. Before starting the debugger, yous need to set at least ane breakpoint to suspend the execution inside the plan. Set a breakpoint at main() method by double-clicking on the left-margin of the line containing main(). A blue circle appears in the left-margin indicating a breakpoint is set at that line.

Step two: Offset Debugger

EclipseJavaDebugStart.png

Right click anywhere on the source code (or from the "Run" menu) ⇒ "Debug Every bit" ⇒ "Java Application" ⇒ choose "Yep" to switch into "Debug" perspective (A perspective is a particular arrangement of panels to suits a certain development task such every bit editing or debugging). The program begins execution only suspends its operation at the breakpoint, i.e., the main() method.

As illustrated in the following diagram, the highlighted line (also pointed to by a blue arrow) indicates the statement to be executed in the next step.

Footstep 3: Step-Over and Watch the Variables and Outputs

EclipseJavaDebugVariables.png EclipseJavaDebugToolbar.png

Click the "Step Over" button (or select "Step Over" from "Run" card) to single-step thru your programme. At each of the footstep, examine the value of the variables (in the "Variable" panel) and the outputs produced by your plan (in the "Console" Panel), if any. You can besides identify your cursor at any variable to inspect the content of the variable.

Single-stepping thru the programme and watching the values of internal variables and the outputs produced is the ultimate mean in debugging programs - because information technology is exactly how the estimator runs your program!

Footstep iv: Breakpoint, Run-To-Line, Resume and Cease

Every bit mentioned, a breakpoint suspends program execution and let you examine the internal states of the program. To set up a breakpoint on a item argument, double-click the left-margin of that line (or select "Toggle Breakpoint" from "Run" menu).

"Resume" continues the program execution, up to the next breakpoint, or till the end of the program.

"Unmarried-footstep" thru a loop with a large count is time-consuming. You could set a breakpoint at the statement immediately outside the loop (e.g., Line eleven of the above programme), and outcome "Resume" to consummate the loop.

Alternatively, you can place the cursor on a particular statement, and issue "Run-To-Line" from the "Run" card to continue execution upwards to the line.

"Terminate" ends the debugging session. Ever terminate your electric current debugging session using "Finish" or "Resume" till the end of the programme.

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 farther programming (or "Window" menu ⇒ Open Perspective ⇒ Java).

Of import: I tin can's stress more that mastering the use of debugger is crucial in programming. Explore the features provided by the debuggers.

Other Debugger's Features

Step-Into and Step-Return: To debug a method, you demand to use "Step-Into" to step into the kickoff statement of the method. ("Stride-Over" runs the office in a single step without stepping through the statements within the office.) You could utilize "Footstep-Return" to render back to the caller, anywhere within the method. Alternatively, you could set a breakpoint inside a method.

Alter the Value of a Variable: You can modify the value of a variable by entering a new value in the "Variable" panel. This is handy for temporarily modifying the beliefs of a plan, without irresolute the source code.

Tips & Tricks

General Usages (for all Programming Tasks)

These are the features that I discover to be most useful in Eclipse:

  1. Maximizing Window (Double-Clicking): You can double-click on the "header" of any panel to maximize that item panel, and double-click once again to restore it back. This feature is specially useful for writing source lawmaking in total panel.
  2. Shorthand Templates (sysout, for,...): You tin type "sysout" followed by a ctrl+infinite (or alt-/) as a shorthand for typing "Arrangement.out.println()".
    The default shortcut key (ctrl-infinite or alt-/) depends on the system. Check your system'due south shortcut central setting in "Edit" ⇒ "Content Assist" ⇒ "Default". Take note that many of you lot apply ctrl+space to switch between input languages. You need to reconfigure either your language switching hot-key or Eclipse.
    Similarly, you can type "for" followed by ctrl-space (or alt-/) to get a for-loop.
    You lot can create your own autograph in "Window" menu ⇒ "Preferences" ⇒ "Coffee" ⇒ "Editor" ⇒ "Templates". (Alternatively, in "Window" ⇒ "Preferences" ⇒ blazon "template" as filter text and choose "Coffee" ⇒ "Editor" ⇒ "Templates".)
    You tin change your key settings in "Window" carte ⇒ "Preferences" ⇒ "General" ⇒ "Cardinal" ⇒ cull "Control", "Content Assist". (Alternatively, in "Window" ⇒ "Preferences" ⇒ type "key" every bit filter text and cull "General" ⇒ "Key".)
  3. Intelli-Sense (ctrl-space): You can use ctrl-space to activate the "intelli-sense" (or content assist). That is, Eclipse will offer yous the choices, while y'all are typing.
  4. Source Formatting (ctrl-shift-f): Right-click on the source. Choose "Source" ⇒ "Format" to let Eclipse to layout your source codes with the proper indentation.
  5. Source Toggle Comment (ctrl-/): To comment/uncomment a block of codes, choose "Source" ⇒ "Toggle Comment".
  6. Hints for Correcting Syntax Fault: If at that place is a syntax mistake on a argument, a red marker volition evidence up on the left-margin on that statement. Y'all could click on the "lite bulb" to display the fault message, and also select from the available hints for correcting that syntax mistake.
  7. Refactor (or Rename) (alt-shift-r): You lot can rename a variable, method, class, package or even the projection easily in Eclipse. Select and correct-click on the entity to be renamed ⇒ "Refactor" ⇒ "Rename". Eclipse can rename all the occurrences of the entity.
  8. Line Numbers: To show the line numbers, choose "Window" menu ⇒ "Preferences" ⇒ "General" ⇒ "Editors" ⇒ "Text Editors" ⇒ Cheque the "Show Line Numbers" Box. You can also configure many editor options, such as the number of spaces for tab. Alternatively, y'all tin right-click on the left-margin, and check "Show Line Numbers".
  9. Mistake Bulletin Hyperlink: Click on an error bulletin will hyperlink to the corresponding source argument.
  10. Changing Font Type and Size: From "Window" menu ⇒ "Preferences" ⇒ "General" ⇒ "Appearance" ⇒ "Colors and Fonts" ⇒ aggrandize "Java" ⇒ "Java Editor Text Font" ⇒ "Edit". (Alternatively, in "Window" ⇒ "Preferences" ⇒ type "font" as filter text and cull the appropriate entry.)
  11. Unicode Support: To enable Unicode support, select "Window" menu ⇒ Preferences ⇒ General ⇒ Workspace ⇒ Text file encoding ⇒ UTF-8. This sets the default grapheme set used for file encoding, similar to VM's command-line choice -Dfile.encoding=UTF-8. Ordinarily used charsets for Unicode are UTF-8, UTF-16 (with BOM), UTF-16BE, UTF-16LE. Other charsets are US-ASCII, ISO-8859-i.
  12. Mouse Hover-over: In debug mode, you could configure to testify the variable's value when the mouse hovers over the variable. Select "Window" card ⇒ "Preferences" ⇒ "Java" ⇒ "Editor" ⇒ "Hover".
  13. Comparing Two Files: In "Package Explorer", select two files (concur the control key) ⇒Right-click ⇒ Compare with.
  14. Setting Keyboard Shortcut Keys: You can set/change the keyboard shortcut keys at "Window" ⇒ "Preferences" ⇒ "General" ⇒ "Key".
    I like to set up the frequently-used commands to Ctrl-1 to Ctrl-10, for examples, "Run Java Awarding" to "Ctrl-1", etc.
  15. Useful Eclipse Shortcut Keys:
    • F3: Goto the proclamation of the highlighted variable/method.
    • Ctrl-Shift-G: Search for ALL references of the highlighted variable/method in workspace.
    • Ctrl-G: Search for the Announcement of a variable/method in workspace.
      Don't utilize Find (Ctrl-F), just utilize the in a higher place context-sensitive search.
    • Ctrl-Shift-F: Format the source code.
    • Ctrl-Shift-O: Organize imports.
    • Alt-Shift-R: Rename. (Don't use Notice/Replace.)
    • Ctrl-Space: auto-complete.
  16. Package Explorer vs. Navigator: We usually utilize "Package Explorer" in programming, but it will not prove you all the folders and files under the project. On the other mitt, "Navigator" is a file manager that shows the verbal file structure of the project (similar to Windows Explorer). You can enable the Navigator by "Window" ⇒ Show view ⇒ Navigator.
  17. Spell Bank check: To enable spell bank check, select Window ⇒ Preferences ⇒ blazon "spell" in the filter ⇒ Full general ⇒ Editors ⇒ Text Editors ⇒ Spelling ⇒ Check "Enable spell checking". Also provide a "User defined dictionary" (with an initially empty text file).
    To right mis-spell words, right-click and press ctrl-1 (or Edit carte ⇒ Quick Fix).
  18. Eclipse'due south Log File: Goto Aid ⇒ virtually Eclipse ⇒ Installation details ⇒ Configuration ⇒ View Error Log.
  19. Viewing two files in split screen: Just click and concur on the title of one file and drag it to the lower side of the screen. [To view the same file on split screen, create a new editor window by selecting Window ⇒ New Editor; and elevate one window to the lower side of the screen.]
  20. Block Select (Cavalcade Select): Push Alt-Shift-A to toggle between block-select mode and normal mode.
  21. Snippets:
    • To view the snippet window: choose "Window" ⇒ Show 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 item.
  22. Give-and-take Wrap (Line Wrap): Word-wrap (or line-wrap) is essential for editing long HTML documents without the horizontal scroll bar. However, the Eclipse's HTML Editor and Text Editor do not support word-wrap.
    Y'all could install a plug-in called "Discussion Wrap" from http://ahtik.com/eclipse-update/.
    Choose "Help" ⇒ Install New Software ⇒ in "Work with" Enter "http://ahtik.com/eclipse-update/".
    To activate give-and-take wrap, correct-click on the editor panel ⇒ select "Word Wrap".
  23. Creating "link folder" in project: You lot practise not accept to identify all the folders nether the project base directory, instead, you tin can employ so-called "link folders" to link to binder outside the project base directory.
    To create a link folder in a project, right-click on the projection ⇒ File ⇒ New ⇒ Folder ⇒ Advanced ⇒ Check Link to alternate Location (Linked Folder).
  24. Running Eclipse in "make clean" mode: You lot tin can run eclipse in so-chosen "make clean" fashion, which wipes all the cached data and re-initialize the cache, by running eclipse from command-line with "-clean" argument (i.due east., "eclipse -clean"). It is useful if something is non working proper, particularly if you install a new copy of Eclipse.
  25. Show the Right Margin: Window ⇒ Preferences ⇒ General ⇒ Editors ⇒ Text Editors ⇒ Show Impress Margin and gear up the column number.
  26. Let me know if you lot have more tips to be included here.

Update Eclipse and Install new Software

  1. Install New Software: Select "Assist" card ⇒ Install New Software ⇒ In "Work With", pull down the select menu and cull a software site.
  2. Update: Select "Assistance" card ⇒ Check for Updates ⇒.

For Java Application Development Just

  1. Small Toy Java Programs: You can keep many small programs (with principal()) in one Java project instead of create a new project for each toy program. To run the desired plan, correct-click on the source file ⇒ "Run equally" ⇒ "Java Application".
  2. Scanner/printf() and JDK i.5: If y'all run into syntax error in using printf() or Scanner (which are available from JDK 1.v), you demand to bank check your compiler settings. Select "Window" menu ⇒ Preferences ⇒ open the "Java" node ⇒ select "Compiler" ⇒ in "Compiler compliance level" ⇒ select the latest release, which should exist "1.5" or to a higher place.
  3. Command-Line Arguments: To provide command-line arguments to your Java plan in Eclipse, correct-click on the source file ⇒ "Run Configurations" ⇒ Under the "Main" panel, check that "Project" name and "Main Course" are appropriate ⇒ Select the "Argument" tab ⇒ type your command-line arguments within the "Program Arguments" box ⇒ "Run".
  4. Resolving Import (Ctrl-Shift-o): To ask Eclipse to insert the import statements for classes. Useful when you re-create a large clamper of codes without the respective import statements.
  5. Including Another Projection: To include some other project in the same work space, right-click on the project ⇒ Build Path ⇒ Configure Build Path... ⇒ Select "Projects" tab ⇒ "Add..." to select projection in the existing work space ⇒ OK.
  6. Exporting a Project to a JAR file: Right-click on the project ⇒ Export... ⇒ Java, JAR File ⇒ Next ⇒ Select the files to exist exported ⇒ Next ⇒ Next ⇒ In "JAR Manifest Specification" dialog, enter the main class (if yous wish to run the JAR file directly) ⇒ Finish.
  7. Unit Testing: If you keep your test in another project, you need to include the project under test in your Build Path (see above).
    To create a test instance: Right-click on the project ⇒ New ⇒ JUnit Exam Case ⇒ the "New JUnit Exam Case" dialog appears. Select "New JUnit 4 Exam". In "Name", enter your class name. In "Course under test", browse and select the class to exist tested.
    To run the examination: Right-click ⇒ "Run Equally" ⇒ "JUnit Test". The results are displayed in a special "JUnit console".
  8. Adding External JAR files & Native Libraries (".dll", ".lib", ".a", ".so"): Many external Java packages (such as JOGL, Java3D, JAMA, etc) are available to extend the functions of JDK. These packages typically provide a "lib" directory containing JAR files (".jar") (Java Archive - a unmarried-file package of Java classes) and native libraries (".dll", ".lib" for windows, ".a", ".so" for Linux and macOS).
    To include these external packages into an Eclipse's project, correct-click on the project ⇒ Build Path ⇒ Add External Archives ⇒ Navigate to select the JAR files (".jar") to exist included.
    In "Package Explorer", right-click on the JAR file added ⇒ Backdrop:
    • To include native libraries (".dll", ".lib", ".a", ".so"), select "Native Library" ⇒ "Location Path" ⇒ "External Binder".
    • 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 "Java Source Attachment".
    All the in a higher place options are also attainable via project'due south belongings ⇒ "Build Path".
    Notes: The JAR files must exist included in the CLASSPATH. The native library directories must exist included in JRE'due south property "java.library.path", which normally only not necessarily includes all the paths from the PATH surround variable. Read "External JAR files and Native Libraries".
  9. Creating a User Library: You can too create a Eclipse'south user library to include a prepare of JAR files and native libraries, that can and then exist added into subsequent Eclipse projects.
    For example, I created a user library for "JOGL" as follows:
    1. From "Window" menu ⇒ Preferences ⇒ Java ⇒ Build Path ⇒ User Libraries ⇒ New ⇒ In "User library proper name", enter "jogl". The "User Library" dialog appears.
    2. In "User Library" dialog ⇒ Select "jogl" ⇒ Add JAR... ⇒ Navigate to <JOGL_HOME>/lib, and select "gluegen-rt.jar" and "jogl.jar".
    3. Expand the "jogl.jar" node ⇒ Select "Native library location: (none)" ⇒ Edit... ⇒ External Folder... ⇒ select <JOGL_HOME>/lib.
    4. Expand the "jogl.jar" node ⇒ Select "Javadoc location: (none)" ⇒ Edit... ⇒ Javadoc in archive ⇒ In "Archive Path", "Scan" and select the downloaded JOGL API documentation zip-file ⇒ In "Path within archive", "Browse" and aggrandize the zip-file to select the acme-level path (if any) ⇒ Validate. Alternatively, you tin can provide the path to the un-zipped javadocs. This is needed for Eclipse to display javadoc data near classes, fields, and methods.
    5. Y'all may provide the source files by editing "Source attachment: (none)". Source is needed but if you lot are interested to debug into the JOGL source codes.
    For EACH subsequent Java project created that uses JOGL, right-click on the project ⇒ Build Path ⇒ Add Libraries ⇒ Select "User Library" ⇒ Check "jogl".
  10. Running an External Program: Suppose that you lot want to run a Perl script on the selected file, you can configure an external tool as follows:
    1. From "Run" carte du jour ⇒ External Tools ⇒ External Tools Configuration... ⇒ The "External Tools Configuration" dialog appears.
    2. In "Proper noun", enter your tool name.
    3. Cull the "Main" 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 resource with absolute path.
    4. Cull the "Common" tab ⇒ In "Standard Input and Output", uncheck "Allocate Panel", bank check "File" and provide an output file (e.yard., d:\temp\${resource_name}.txt).
    5. (If you use the CYGWIN perl interpreter, need to ready environment variable CYGWIN=nodosfilewarning to disable warning bulletin.)
    To run the configured external tool, select a file ⇒ run ⇒ external tool ⇒ tool proper noun.
  11. Viewing Hex Code of Primitive Variables in Debug way: In debug perspective, "Variable" panel ⇒ Select the "menu" (inverted triangle) ⇒ Java ⇒ Java Preferences... ⇒ Archaic Display Options ⇒ Check "Display hexadecimal values (byte, short, char, int, long)".
  12. Adding a New Version of JDK/JRE: Outset, you can bank check the installed JDK/JRE via "Window" menu ⇒ "Preferences" ⇒ Expand "Coffee" node ⇒ "Installed JREs". Bank check the "Location" current JRE installed to make sure that it is the intended one. Yous tin use the "Add" button to add a new version of JRE. For program development, I recommend that you add the JDK (instead of JRE). [The "Location" decides the extension directory used for including boosted JAR files, e.g., $JAVA_HOME\jre\lib\ext.]

For Web Developers

  1. HTML Editor: Use the "Spider web Page Editor" (available in Eclipse Java EE), which provides the design view (WYSISYG).
    To use the "Spider web Folio Editor", right-click on the HTML file, open equally "Web Page Editor".
    To make the "Web Page Editor" every bit default for HTML file, goto Window ⇒ Preferenes ⇒ 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 program, which inputs from a text file chosen "xxxx.in" and outputs to a text file called "xxxx.out". This is a little tricky under Eclipse due to:

  1. When you create a text file in Windows' Notepad and saved it as "xxxx.in", Notepad will append the ".txt" to your file and it becomes "xxxx.in.txt". Worse still, the Windows' Explorer, by default, volition not show the ".txt" extension. (The start thing I always do to an alien figurer is to change this setting. From "Tools" menu ⇒ Folder Options... ⇒ View ⇒ Uncheck "Hide extensions for known file types".) Y'all need to put a pair of double quotes effectually xxxx.in to override the default ".txt" extension. This is i proficient reason not to use Notepad for programming at all. You lot should employ Eclipse to create the text file instead.
  2. Which directory to keep the input file "xxxx.in" in Eclipse?
    • If you did non split the sources and grade files into two split directories, and so the answer is straight forward, because there is but one directory to identify your input file.
    • If you cull to keep your sources and class files in two separate directories, eclipse will create two sub-directories "src" and "bin" under the base directory. BUT yous demand to put your input file "xxxx.in" in the base directory of your projection, instead of the "src" or "bin"..

For writing simple programs:

  • Put the sources, class files, and the input/output files in the same directory. (When y'all create a new project, select "Use project binder as root for sources and course files" in "Project Layout".) (Merely put your sources and class files in split directories for big project.)
  • You can create you input file from eclipse directly via "File" menu ⇒ "New" ⇒ "File".
  • Remember to add together a newline to the terminate of your input file.
  • You lot may need to right-click the project and select "Refresh" to see the output file "xxxx.out" created in the package explorer.
  • To open the "xxxx.in" and "xxxx.out": right-click ⇒ Open With ⇒ Text Editor.

This is a sample JDK i.5 programme for file input/output:

import java.util.Scanner; import java.util.Formatter; import java.io.File; import coffee.io.IOException;     public class          FileIOTest          {      public static void main (String [] 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\n",a+b);             out.shut();        } }

Create the input text file called "FileIOTest.in" with the following 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.

Step 0: Install WindowBuilder

To install "WindowBuilder", goto "Help" ⇒ Install New Software ⇒ In "Work with", enter "https://download.eclipse.org/windowbuilder/latest/" (You tin can discover the proper link from "http://www.eclipse.org/windowbuilder/download.php") ⇒ Bank check "WindowBuilder" ⇒ Next ⇒ Next ⇒ Accept the licence ⇒ Cease.

Footstep 1: Create a New "Coffee Application" Project
  1. Cull "File" menu ⇒ "New" ⇒ "Java project".
  2. The "New Java Project" dialog pops up.
    1. In the "Projection proper name" field, enter "FirstSwingProject".
    2. Check "Use default location".
    3. In the "JRE" box, select "Use default JRE (currently 'JDK1.ten')".
    4. Click "Finish".
Step 2: Create a Swing JFrame Bracket
  1. Cull "File" bill of fare ⇒ "New" ⇒ "Others" ⇒ "WindowBuilder" ⇒ "Swing Designer" ⇒ "JFrame" ⇒ "Adjacent".
  2. In the "Create JFrame" dialog ⇒ Enter "SwingMain" in the "Proper name" field ⇒ "Finish".
  3. Select the "Design" pane.
  4. In "Layouts", select "FlowLayout" and click on the "design class".
  5. From "Components", select "JLabel" and click on the design class. Change the characterization text to "Counter: ". Select a "JTextField" and place it on the design form. Change the text to "0". Select a "JButton" and place it on the blueprint class. Change the text label to "Count".
  6. To attach a event-handler to the button, double-click the JButton to switch into the "Source" pane, with the event-handler skeleton created. Complete the actionPerformed() as follows:
    public void actionPerformed(ActionEvent due east) {              count++;    textField.setText(count + "");               }
    Add an instance variable called count as follow:
    public class SwingMain extends JFrame {              private int count = 0;              ......
  7. You can now ready run the program. Right-click on the project ⇒ Run As ⇒ Java Awarding.
Eclipse Generated Codes

Study the codes generated past Eclipse GUI Architect, every bit follows, which is merely a typical Swing awarding.

1 2 3 4 5 six 7 8 nine 10 11 12 13 14 xv sixteen 17 18 nineteen 20 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 fifty 51 52 53 54 55 56 57 58 59
import java.awt.*; import coffee.awt.upshot.*; import javax.swing.*; import javax.swing.border.EmptyBorder;   public form SwingMain extends JFrame {            private JPanel contentPane;    individual JTextField textField;    private int count = 0;          public static void master(String[] args) {       EventQueue.invokeLater(new Runnable() {            @Override          public void run() {             try {                SwingMain frame = new SwingMain();                frame.setVisible(true);             } catch (Exception e) {                e.printStackTrace();             }          }       });    }          public SwingMain() {       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       setBounds(100, 100, 450, 300);       contentPane = new JPanel();       contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));       setContentPane(contentPane);       contentPane.setLayout(new FlowLayout(FlowLayout.Middle, 5, 5));         JLabel lblNewLabel = new JLabel("Counter: ");       contentPane.add(lblNewLabel);         textField = new JTextField();       textField.setText("0");       contentPane.add together(textField);       textField.setColumns(10);         JButton btnCount = new JButton("Count");       btnCount.addActionListener(new ActionListener() {          @Override          public void actionPerformed(ActionEvent east) {             count++;             textField.setText(count + "");          }       });       contentPane.add(btnCount);    } }

Eclipse for C/C++ Programming

Hither.

Eclipse PDT (PHP Development Tool)

Hither.

Eclipse-JavaEE and Database Evolution

Reference: "Information Tools Platform User Documentation" @ Eclipse Welcome page.

You need to install:

  1. "Eclipse for Java EE" (aka "Eclipse IDE for Enterprise Java Developers").
  2. "MySQL Customs Server" and "MySQL Connector/J Driver". Read "How to install and get started with MySQL".

To utilise Eclipse for MySQL development:

  1. Switch to "Database Evolution" perspective:
    From "Window" menu ⇒ Open up Perspective ⇒ Other ⇒ Database Development.
  2. Create a Database Connection: Kickoff your MySQL database server ⇒ Right-click "Database Connection" ⇒ New. Take note that each database connectedness connect to ONE particular database in the database server with a URL in the course of jdbc:mysql://localhost:3306/database-name.
    1. In "Connection Contour", cull "MySQL" ⇒ Next.
    2. In "Drivers", click the icon for "New Driver Definition" (if the commuter has not been divers).
    3. In "Specify a Driver Template and Definition Name":
      1. Cull the "Proper noun/Type" tab ⇒ Choose one of the database driver equally our template (e.g. MySQL five.1) for further customization ⇒ Set your "Commuter name", east.yard., "mysql-connector-java-8.0.23".
      2. Switch to "JAR List" tab ⇒ Clear All ⇒ Click "Add JAR/Zilch" and select the driver JAR file, e.m., mysql-connector-coffee-8.0.23.jar.
      3. Switch to "Properties" tab ⇒ Cheque the parameters.
      4. OK.
      5. Enter the "Database" proper noun, URL (with the same database name), and the "Password" ⇒ Click "Test Connection"
      6. Finish.
    4. In "Datasource Explorer", you can "connect" and "disconnect" the connection.
  3. To view and edit table visually, expand database "Schemas" to wait for the table. Right-right on the table ⇒ Data ⇒ Edit. You can modify the cells and "save" the changes.
  4. To create a new SQL script, choose File ⇒ New ⇒ SQL File ⇒ Yous may utilize an existing projection or create a new projection (Full general|Project or Web|Dynamic Spider web Project) ⇒ Enter filename, and ready the connection profile name ⇒ Finish. Enter a SQL statement (east.g., SELECT * FROM tablename) ⇒ Right-click on the text ⇒ "Execute Electric current Text" or "Execute All".
  5. To use an existing SQL file, drop the file into a project and open the SQL file. In Connection contour, set the type and connection proper name. Correct-click on a statement ⇒ "Execute ...".

Developing and Deploying Webapps in Eclipse-JavaEE

Setting Up Eclipse-JavaEE for Web Evolution

  1. Install "Eclipse for Coffee EE" (aka "Eclipse IDE for Enterprise Coffee Developers").
  2. Install Tomcat (or Glassfish) server.
  3. Configuring Web Server: Launch Eclipse ⇒ Window ⇒ Preferences ⇒ Expand the "Server" node ⇒ "Runtime Environments" ⇒ "Add together..." ⇒ Expand "Apache" and select "Apache Tomcat vX.X" ⇒ Enter your "Tomcat Installation Directory" ⇒ "Finish".

Writing a How-do-you-do-earth Servlet

  1. Switch to "Java EE" perspective (which is the default perspective for Eclispe-JavaEE):
    From "Window" carte ⇒ Open Perspective ⇒ Other ⇒ Java EE.
  2. Create a new Web Application Projection: from "File" ⇒ New ⇒ Dynamic Spider web Project (nether "Web" category) ⇒ In "Project Name", enter "HelloServletProject" ⇒ "End".
  3. Create a new Servlet: Correct-click on the project "HelloServletProject" ⇒ New ⇒ Servlet ⇒ In "Java Package", enter "mypkg"; in "Course Name", enter "HelloServlet" ⇒ Next ⇒ In "URL Mappings", select "/HelloServlet" ⇒ "Edit" to "/sayhello" ⇒ Next ⇒ In "Which method stubs would yous like to create", check "Inherited abstruse method", "doGet" and "doPost" (default) ⇒ Finish.
    In "HelloServlet.java", enter the following codes:
    package mypkg;  import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.notation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;   @WebServlet("/sayhello") public class HelloServlet extends HttpServlet {    private static concluding long serialVersionUID = 1L;         public HelloServlet() {       super();           }         protected void doGet(HttpServletRequest asking, 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("<body>");       out.println("<h1>How-do-you-do Globe, from Servlet!</h1>");       out.println("<p>Method: " + asking.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 Accost: " + asking.getRemoteAddr() + "</p>");              out.println("<p>Generate a Random Number per request: <strong>" + Math.random() + "</strong></p>");       out.println("</body>");       out.println("</html>");    }         protected void doPost(HttpServletRequest asking, HttpServletResponse response)          throws ServletException, IOException {              doGet(request, response);    } }

    (For Servlet 2.iv/2.v with Tomcat half dozen) The note @WebServlet is new in Servlet iii.0 and is non supported in Servlet two.four/2.5. Hence, you lot demand to manually configure the URL for the servlet in the Web Application Deployment Descriptor "spider web.xml" under directory "Web-INF", every bit follows:

    <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://coffee.sunday.com/xml/ns/javaee"   xmlns:xsi="http://world wide web.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"   version="3.0" metadata-complete="true">     <servlet>     <servlet-proper noun>HelloServletExample</servlet-proper name>     <servlet-course>mypkg.HelloServlet</servlet-class>   </servlet>     <servlet-mapping>     <servlet-proper name>HelloServletExample</servlet-proper noun>     <url-design>/sayhello</url-pattern>   </servlet-mapping>   </web-app>
  4. To execute the Servlet, right-click on the "HelloServletProject" ⇒ "Run As" ⇒ "Run on Server" ⇒ Alter the URL to "http://localhost:8080/HelloServletProject/sayhello".

Writing a Hello-globe JSP (Coffee Server Pages)

  1. Create a new Spider web Application: File ⇒ New ⇒ Dynamic Web Project (under "Web" category) ⇒ In "Project Proper noun", enter "HelloJSPProject" ⇒ Finish.
  2. Create a new JSP File: Right-click on the project "HelloJSPProject" ⇒ New ⇒ JSP File ⇒ The parent folder shall be "HelloJSPProject/WebContent" ⇒ In "File Name", enter "hello.jsp" ⇒ "Finish".
  3. Enter the post-obit HTML/JSP codes:
    <%@ folio linguistic communication="java" contentType="text/html; charset=ISO-8859-1"     pageEncoding="ISO-8859-1"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Hi JSP</title> </caput> <trunk> <h1>Hello World, from JSP</h1> <p>Method:              <%= request.getMethod() %></p> <p>Request URI:              <%= asking.getRequestURI() %></p> <p>Protocol:              <%= request.getProtocol() %></p> <p>PathInfo:              <%= request.getPathInfo() %></p> <p>Remote Address:              <%= asking.getRemoteAddr() %></p>              <% double num = Math.random(); if (num > 0.75) { %>              <h2>You'll have a lucky day!</h2><p>(<%= num %>)</p>              <% } else { %>              <h2>Well, life goes on ... </h2><p>(<%= num %>)</p>              <% } %>              <h3><a href="<%= asking.getRequestURI() %>">Try Again</a></h3> </body> </html>
  4. To execute the JSP, right-click on "hello.jsp" ⇒ Run Equally ⇒ Run on Server.

Exporting a Webapp equally a WAR file

Right-click on the project to exist exported ⇒ Export ⇒ State of war File ⇒ In "Destination", specify the destination directory and filename (the filename shall be the spider web awarding name) ⇒ Finish.

  1. To deploy the state of war file in Tomcat, simply drop the war file into Tomcat'southward "webapps" folder. The war file will be automatically extracted and deployed. The web application name is the war-filename.
  2. You could use WinZip (or WinRAR) to view the content of the war file, equally state of war-file is in ZIP format.

Deploying a webapp outside the Tomcat'due south webapps directory

To deploy a webapp (chosen hello) outside the %TOMCAT_HOME%\webapps directory, create a hello.xml file equally follows and place it under the %TOMCAT_HOME%\conf\Catalina\localhost:

<Context displayName="hullo"      docBase="C:\path\to\webapp"      path="/hello"      reloadable="true" />        

Writing a Hello-world JSF (JavaServer Faces)

[TODO]

Debugging Webapps

You lot can debug a webapp just like standalone application. For example, you can set breakpoints, unmarried-step through the programs, etc.

REFERENCES & Resources

  1. Eclipse mother site @ https://www.eclipse.org.
  2. Eclipse documentation and user guides, accessible via Eclipse's Help and menu.

Latest version tested: Eclipse Java and Eclipse JavaEE 2021-12
Last modified: Jan 2022

callihanstor1972.blogspot.com

Source: https://www3.ntu.edu.sg/home/ehchua/programming/howto/eclipsejava_howto.html

0 Response to "Eclipse How to Run Program Again With Arguments"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel