Home > Java > javaTutorial > A simple tutorial to quickly create a Maven project

A simple tutorial to quickly create a Maven project

WBOY
Release: 2024-02-19 11:32:22
Original
1201 people have browsed it

A simple tutorial to quickly create a Maven project

IDEA (IntelliJ IDEA) is a powerful integrated development environment that can facilitate developers to develop and manage Java projects. Maven is a Java project management tool that can help manage project dependencies, build projects, etc. This article will introduce how to create a new Maven project in IDEA, and attach specific code examples.

Step 1: Create a new Maven project

  1. Open IDEA and click "File" -> "New" -> "Project" in the menu bar.
  2. Select "Java" in the pop-up window, and then click "Next".
  3. On the project template selection page, select "Maven" and click "Next".
  4. Enter the name and storage path of the project and click "Finish".

Step 2: Configure Maven

  1. Open the project's pom.xml file and you can see the Maven configuration file.
  2. In the tag, configure the basic information of the project, such as groupId, artifactId, version, etc.
  3. In the tag, add the dependencies required by the project. For example, the following is an example that adds a JUnit dependency:
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>
Copy after login

Step 3: Create a Java class

  1. Create a new Java class in the src/main/java directory. For example "HelloWorld.java".
  2. Write a simple Java program, such as the code to output "Hello, World!":
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Copy after login

Step 4: Run the project

  1. In IDEA , click the green run button on the top toolbar, or use the shortcut key Shift F10 to run the project.
  2. You should be able to see the output "Hello, World!" in the console.

Through the above steps, you have successfully created a new Maven project in IDEA, and written and run a simple Java program. Hope this simple guide helps!

The above is the detailed content of A simple tutorial to quickly create a Maven project. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template