A Java project set up using IntelliJ IDEA
With this part of the Java challenges project, I provide the code and settings for a Java project set up using IntelliJ IDEA.
Below, I give background information on the project’s code and IntelliJ IDEA’s configuration. I also discuss issues that can occur when setting up a Java project using IntelliJ IDEA.
This project makes use of Java. I describe this programming language in the Java section of the Java challenges project.
For demonstrative purposes, the current project contains only a single Java class called Main
, which consists of a main
method outputting a well-known message:
package nl.mauritssilvis.challenges.java.intellij.manual.projects.basic;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
This project is set up using IntelliJ IDEA (see, e.g., the IntelliJ IDEA section of the Java challenges project).
The IntelliJ IDEA configuration is described in what follows.
The .idea folder of this project contains several IntelliJ-IDEA-related configuration files. A few of these files are highlighted below.
First, Unix-style line endings are selected in the file Project.xml, which facilitates cross-platform coding. In addition, rulers are shown at 80 characters:
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<option name="LINE_SEPARATOR" value="&#10;" />
<option name="SOFT_MARGINS" value="80" />
</code_scheme>
</component>
Automatic copyright messages, including the current year and an SPDX license identifier for the GNU General Public License v3.0, are configured in the file GNU_GPL_v3.xml:
<component name="CopyrightManager">
<copyright>
<option name="notice" value="Copyright © &#36;today.year Maurits Silvis SPDX-License-Identifier: GPL-3.0-or-later" />
<option name="myName" value="GNU GPL v3" />
</copyright>
</component>
A code inspection profile in which all Java-21-compatible IntelliJ IDEA inspections are turned on is provided in All.xml. This profile facilitates learning about possible code improvements and optimizations. A profile in which only the default inspections are selected is stored in Default.xml.
This project comes with a run configuration for executing the main
method of the Main
class.
This project is configured to run with the Adoptium distribution of the Java Development Kit (JDK) 21. This setting can be reviewed in IntelliJ IDEA’s project settings or the file misc.xml.
While setting up and executing a Java project using IntelliJ IDEA, you may encounter several issues. Below, I discuss problems related to the configuration of IntelliJ IDEA.
When you open this project, IntelliJ IDEA may show one or more of the following warnings:
Project JDK is not defined
JDK "temurin-21" is missing
To solve these warnings and be able to execute the project’s code, configure the project JDK in IntelliJ IDEA’s project settings. You can either select one of the listed JDKs or opt for the Adoptium distribution of the Java Development Kit (JDK) by following the Installation section of Setting up a Java project using the command line and selecting that JDK.
Copyright © 2021–2023 Maurits Silvis
This source code package is subject to the terms and conditions defined in the GNU General Public License v3.0 or later.