Write Hello World in Java Using Eclipse and Maven

 Learn how to create your first Hello World program in Java using Eclipse and Maven. 1. Introduction This blog will teach you how you can le...

 Learn how to create your first Hello World program in Java using Eclipse and Maven.

1. Introduction

This blog will teach you how you can leverage the maven archetype to create a project in Java.

1.1 Requirements

You must have the following installed on your local machine.

  • OpenJDK 11
  • Maven
  • Eclipse

2. Create the Java Project

2.1 Run Eclipse.

2.2 Inside Eclipse select File / New / Other.

2.3 In the Select a Wizard view, type maven and select Maven Project and click Next.

2.4 In the next view, you can uncheck the "Use default Workspace location" to select where you want to save your project. In our case, we will use the Workspace directory. Click Next.

2.5 In the following screen select or set the following:
Catalog=Maven Central
And select the row with version 1.4 (at the time of writing, could be greater than now).
Click Next.

2.6 In the Specific Archetype parameters window enter the following:
Group Id=com.czetsuyatech (or it can be your own domain name)
Artifact Id=hello-world
Click Finish.

2.7 If the maven project is successfully created, you should be able to see the screenshot below.

3. Set the correct Java version.

If you read my previous blog you should know that we are using OpenJDK 11 for this exercise thus, we need to set our project to use JDK 11.

And there are 2 places we have to modify.

3.1 JRE System Library

3.1.1 Right-click on JRE System Library, select Build Path / Configure Build Path

3.1.2 Make sure the JRE System Library is selected under the Libraries tab. If you see OpenJDK 11, do nothing else click Edit.

3.1.3 In the next screen, you can set the Execution environment to OpenJDK-11 OR select Workspace default (if it is OpenJDK-11). Either one should work as long as it's OpenJDK-11.

Another thing you should check is if whether OpenJDK is successfully added to your machine. We already set it in the previous blog but for the sake of verification. Click Environments / JavaSE-11 / OpenJDK-11 (make sure that it exists and that it is check). Otherwise, you have to add it by clicking the installed JREs button and add the folder where you install the OpenJDK 11.

3.1.4 If the operation is successful, your project should be updated like this:

4.  Set the project Java Compiler to Java 11, so that Eclipse knows that you are building on this version and enable its available features. (Hang on, we're almost there).

4.1 Right-click on the project, and select Properties.

4.2 In the following view, select Java Compiler and click the "Enable project specific settings". Set the Compiler compliance level to 11. Finally, click Apply and Close.

After this, you're now set to create and code Java classes.

*If you are looking for IntelliJ guide here's the link


java-hello-world 2277599645431712

Post a Comment Default Comments