How to create a Maven project in Java?

To create a Maven project, you can follow these steps:

  1. Install Maven: Make sure that Maven is installed on your computer first. You can download and install Maven from the official Maven website.
  2. To create a Maven project, open a command line window, navigate to the directory where you want to create the project, and run the following command to create a new Maven project.
mvn archetype:generate -DgroupId=com.example -DartifactId=my-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

In this case, com.example is the groupId of the project, and my-project is the artifactId of the project. You can also modify these parameters as needed.

  1. Navigate to the project directory: After the project is created, go to the project directory:
cd my-project
  1. Compile the project: run the following command to compile the project:
mvn compile
  1. To run the project: If the project is a Java application, you can use the following command to run the project:
mvn exec:java -Dexec.mainClass="com.example.App"

In this situation, com.example.App is the entry class for your application.

By following the steps above, you can successfully create a Maven project and run it.

bannerAds