Create a Java project with Maven

Prerequisites

Java and Maven -> See How to install Java and Maven on MacOS, Linux and Windows

Create a new Java project with Maven

Open a terminal and run:

sh
mvn archetype:generate \ -DgroupId=com.mycompany.app \ -DartifactId=my-app \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DarchetypeVersion=1.4 \ -DinteractiveMode=false

This command will create a folder with the same name as the artifactId and the following structure:

my-app |-- pom.xml `-- src |-- main | `-- java | `-- com | `-- mycompany | `-- app | `-- App.java `-- test `-- java `-- com `-- mycompany `-- app `-- AppTest.java

You can change the target & source compiler versions:

xml
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>17</source> <target>17</target> </configuration> </plugin> </plugins>

source: https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Build the project

Run:

sh
mvn package

Run the built app:

sh
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App