Create a Java project using Eclipse

Introduction

Operating environment

Development environment construction ①: OpenJDK 11 installation

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.

  1. 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/

  2. 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/

  3. Click Windows / x64 Java Development Kit. https://jdk.java.net/java-se-ri/11

  4. "openjdk-11 + 28_windows-x64_bin.zip" will be downloaded.

  5. 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.)

  6. 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)
    

Development environment construction (2): Eclipse installation

After the OpneJDK installation is complete, install Eclipse.

  1. 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/

  2. When you are on the download page, click the Download button.

  3. eclipse-java-2020-06-R-win32-x86_64.zip will be downloaded.

  4. 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.)

Eclipse initial 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.

  1. Execute the main menu "Window"> "Preferences" to launch the "Preferences" dialog.

  2. Select Java> Installed JREs from the tree on the left and make sure the OpenJDK 11 path is set.

  3. 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.

  4. 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.)

  5. Press the Apply and Close button.

Project creation

First, create a project.

  1. Click File> New> Java Project on the main menu to launch the New Java Project dialog.

  2. 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.)

  3. When the "New module-info.java" dialog is launched, press the "Don't Create" button.

  4. Confirm that the sample project tree has been generated on "Package Explorer".

Create main class

Next, create the main class (the class that contains the main method).

  1. 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.

  2. 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.)

  3. 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
    	}
    
    }
    
  4. 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 }

}
~~~

Build

For builds, enable automatic builds so that they build automatically.

  1. 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. ..

  2. 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

Run it when you have a build.

  1. Click Run> Run Configurations on the main menu.

  2. Double-click Java Application in the tree of the Run Configurations dialog to add the child node New_Configuration.

  3. Change the "Name" field to the main class name "SampleMain" and press the "Apply" button to update the child node "New_Configuration" to "SampleMain".

  4. 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.

  5. Press the Run button in the Run Configurations dialog, or press the Run button on the icon.

  6. In the "Console" window, you will see "Hello Hello".

debug

If you want to debug, do the following:

  1. Click Run> Debug Configurations on the main menu.

  2. Double-click Java Application in the tree of the Debug Configurations dialog to add a child node New_Configuration.

  3. Change the "Name" field to the main class name "SampleMain" and press the "Apply" button to update the child node "New_Configuration" to "SampleMain".

  4. 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. ..

  5. Press the "Debug" button in the tree of the "Debug Configurations" dialog or the "Debug" button on the icon to start debugging.

  6. Since we have checked "Stop in main", we will break at the beginning of the main method.

  7. 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

Create a Java project using Eclipse
Create a Jetty project using Eclipse
Create a tomcat project using Eclipse
Create a tomcat project using Eclipse Pleiades All in One
Eclipse ~ Java project creation ~
[Java] Create a filter
Create a java method [Memo] [java11]
[Java] Create a temporary file
Create a fortune using Ruby
Make a rhombus using Java
Create a portfolio app using Java and Spring Boot
Create a Java development environment using jenv on Mac
[Android] Create a calendar using GridView
Create a base for your batch processing project in Eclipse.
Upload a file using Java HttpURLConnection
[Java] How to create a folder
Create a filtering function using acts-as-taggable-on
Create a Servlet program in Eclipse
Create a MOB using the Minecraft Java Mythicmobs plugin | Preparation 1
Create a Maven project with a command
Create a memo app with Tomcat + JSP + Servlet + MySQL using Eclipse
How to create a new Gradle + Java + Jar project in Intellij 2016.03
[Java] Create and apply a slide master
Create a web environment quickly using Docker
Create Java Spring Boot project in IntelliJ
Let's create a Java development environment (updating)
Connect from Java to MySQL using Eclipse
Create a TODO app in Java 7 Create Header
Create a RESTful API service using Grape
Deploy a Tomcat-based Eclipse project on Heroku
Create a prefectural select bar using active_hash
Create a login function using Swift's Optional
Create Maven Project
Creating a project (and GitHub repository) using Java and Gradle in IntelliJ IDEA
Create API using Retrofit2, Okhttp3 and Gson (Java)
[Android] Create a sliding menu without using NavigationView
Create a Privoxy + Tor environment instantly using Docker
Create a CSR with extended information in Java
Create a simple bulletin board with Java + MySQL
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Let's create a timed process with Java Timer! !!
[Rails] How to create a graph using lazy_high_charts
Create a Lambda Container Image based on Java 15
[Java] API creation using Jerjey (Jax-rs) in eclipse
Create a simple batch processing framework in Eclipse.
[Java] Create something like a product search API
Try to create a bulletin board in Java
Create a Spring Boot application using IntelliJ IDEA
[Java] Create a collection with only one element
Let's create a super-simple web framework in Java
[Java] Let's create a mod for Minecraft 1.14.4 [Introduction]
Create Scala Seq from Java, make Scala Seq a Java List
[Java] Let's create a mod for Minecraft 1.16.1 [Introduction]
Java tips-Create a Spring Boot project in Gradle
[1st] How to create a Spring-MVC framework project
[Java] Let's create a mod for Minecraft 1.14.4 [99. Mod output]
Ssh connect using SSHJ from a Java 6 app
[Note] Java: Create a simple project while learning how the configuration file works.
[Java] Let's create a mod for Minecraft 1.14.4 [0. Basic file]
Sorting using java comparator
[Java] Let's create a mod for Minecraft 1.14.4 [4. Add tools]