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
- Open IDEA and click "File" -> "New" -> "Project" in the menu bar.
- Select "Java" in the pop-up window, and then click "Next".
- On the project template selection page, select "Maven" and click "Next".
- Enter the name and storage path of the project and click "Finish".
Step 2: Configure Maven
- Open the project's pom.xml file and you can see the Maven configuration file.
- In the tag, configure the basic information of the project, such as groupId, artifactId, version, etc.
- 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
- Create a new Java class in the src/main/java directory. For example "HelloWorld.java".
- 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
- In IDEA , click the green run button on the top toolbar, or use the shortcut key Shift F10 to run the project.
- 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!