JRE (Java Runtime Environment) is required to run Eclipse. Here, download OpenJDK to get the JRE. If you do not have JRE installed, you will get an error when starting Eclipse, so you need to do it before installing Eclipse.
Go to the official OpenJDK website below and click the jdk.java.net/14
link in the Download section. (The link for jdk.java.net/14
changes every time OpenJDK is upgraded.)
https://openjdk.java.net/
Click Java SE 11 in the list of links on the left. (If you want to download the latest version of OpenJDK, you can download OpenJDK from this site.) https://jdk.java.net/14/
Click Windows / x64 Java Development Kit. https://jdk.java.net/java-se-ri/11
"openjdk-11 + 28_windows-x64_bin.zip" will be downloaded.
When the download is complete, unzip it to any folder and add the absolute path of "jdk-11 \ bin" to your system environment variables. (Here, I unzipped it to C: \ openjdk and added "C: \ openjdk \ jdk-11 \ bin" to the system environment variables.)
Start a command prompt and check the Java version. (If it is openjdk 11, it is OK.)
>java --version
openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
After the OpneJDK installation is complete, install Eclipse.
Go to the Eclipse package installer download site and click "Windows 64-bit" in the "Eclipse IDE for Java Developers". https://www.eclipse.org/downloads/packages/
When you are on the download page, click the Download button.
eclipse-java-2020-06-R-win32-x86_64.zip will be downloaded.
When the download is complete, unzip it to any folder and double-click "eclipse.exe". (You will be required to enter the workspace folder path at startup, but leave the default settings.)
Initialize Eclipse before creating a project. If you set it once at the beginning, you do not need to set it from the next time.
Execute the main menu "Window"> "Preferences" to launch the "Preferences" dialog.
Select Java> Installed JREs from the tree on the left and make sure the OpenJDK 11 path is set.
Set the character code. Here, we will change it for Linux assuming that it will also work on Linux. Select "General"> "Workspace" from the tree on the left, check "Other" in "Text file encoding", and select "UTF-8". Also, check "Other" in "New text file line delimiter", select "Unix", and press the "Apply" button.
Change the font to prevent garbled characters. Select "General"> "Appearance"> "Colors and Fonts" from the tree on the left, select "Java Editor Text-Font", and press the "Edit" button to launch the "Fonts" dialog. Change the font in the "Font" dialog and press the "Apply" button. (Here, I changed to MS Gothic. Depending on the font you select, the characters may be garbled, so select a font that does not garble.)
Press the Apply and Close button.
First, create a project.
Click File> New> Java Project on the main menu to launch the New Java Project dialog.
Enter the project name in the "Project name" field and press the "Finish" button. (Here, the project name is "sample" and other settings are left as default.)
When the "New module-info.java" dialog is launched, press the "Don't Create" button.
Confirm that the sample project tree has been generated on "Package Explorer".
Next, create the main class (the class that contains the main method).
Select the top node of the tree on "Package Explorer", right-click and click the pop-up menu "New"> "Class" to launch the "New Java Class" dialog.
Enter the class name in the "Name" field, check "public static void main (String [] args)", and click the "Finish" button. (Here, enter "SampleMain" in the "Name" field.)
The "sample"> "src"> "sample"> "SampleMain.java" node is added to the tree on "Package Explorer". The code for SampleMain.java looks like this:
package sample;
public class SampleMain {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
Add any code to the source code of SampleMain.java.
package sample;
public class SampleMain {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println ("Hello"); // Add System.out.println ( "Hello"); // add }
}
~~~
For builds, enable automatic builds so that they build automatically.
Select the top node of the tree on "Package Explorer", right-click and click the pop-up menu "Reflesh" to automatically update the file structure of the tree on "Package Explorer" to the current state. ..
Check "Project"> "Build Automatically" in the main menu to enable automatic build. (If the build is not executed, click "Project"> "Clean" in the main menu.)
Run it when you have a build.
Click Run> Run Configurations on the main menu.
Double-click Java Application in the tree of the Run Configurations dialog to add the child node New_Configuration.
Change the "Name" field to the main class name "SampleMain" and press the "Apply" button to update the child node "New_Configuration" to "SampleMain".
Open the "Main" tab, enter the project name in the "Project" field and the class name including the main method in the "Main class" field, and press the "Apply" button.
Press the Run button in the Run Configurations dialog, or press the Run button on the icon.
In the "Console" window, you will see "Hello Hello".
If you want to debug, do the following:
Click Run> Debug Configurations on the main menu.
Double-click Java Application in the tree of the Debug Configurations dialog to add a child node New_Configuration.
Change the "Name" field to the main class name "SampleMain" and press the "Apply" button to update the child node "New_Configuration" to "SampleMain".
Open the "Main" tab, enter the project name in the "Project" field and the class name including the main method in the "Main class" field, check "Stop in main" and press the "Apply" button. ..
Press the "Debug" button in the tree of the "Debug Configurations" dialog or the "Debug" button on the icon to start debugging.
Since we have checked "Stop in main", we will break at the beginning of the main method.
Set a breakpoint with Ctrl + Shift + b and press F8 (Run) to break at the location where you set the breakpoint. You can also step in with the F5 key and step out with the F6 key.
Recommended Posts