Close Menu
Java HelpsJava Helps
    What's Hot

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022
    Facebook X (Twitter) Instagram
    Java HelpsJava Helps
    • Home
    • How To
      1. Install
      2. Run
      3. Configure
      4. View All

      How to Install MySQL with phpMyAdmin on Ubuntu?

      December 4, 2022

      Install The Latest IntelliJ IDEA on Linux

      November 28, 2022

      Install The Latest Apache Maven on Linux

      November 27, 2022

      Install The Latest Oracle JDK on Linux

      November 27, 2022

      Run NiFi Cluster in Docker with SSL Enabled

      December 6, 2022

      How to Run Apache NiFi Docker on Mac M1?

      December 1, 2022

      How to Run Apache NiFi on Docker?

      December 1, 2022

      Create A New Maven Project In IntelliJ IDEA

      November 29, 2022

      Things To Do After Installing IntelliJ IDEA

      December 20, 2022

      How to Set Proxy for IntelliJ IDEA?

      December 20, 2022

      How to Set Proxy for Maven?

      December 6, 2022

      How to Create a Fat JAR Using Maven?

      December 5, 2022

      Things To Do After Installing IntelliJ IDEA

      December 20, 2022

      How to Set Proxy for IntelliJ IDEA?

      December 20, 2022

      Manage GitHub Artifact Storage Quota

      December 6, 2022

      Run NiFi Cluster in Docker with SSL Enabled

      December 6, 2022
    • Hello World
      1. Framework
      2. Library
      3. View All

      JPA Hello World! using Hibernate and MySQL

      December 3, 2022

      Jersey 3.x – Hello World!

      December 2, 2022

      Microservices Framework for Java (MSF4J) – Hello World!

      December 1, 2022

      How to Parse PCAP files in Java?

      November 30, 2022

      JPA Hello World! using Hibernate and MySQL

      December 3, 2022

      Jersey 3.x – Hello World!

      December 2, 2022

      Microservices Framework for Java (MSF4J) – Hello World!

      December 1, 2022

      How to Parse PCAP files in Java?

      November 30, 2022
    • More
      • Privacy Policy
        • Java Helps
        • Android Apps
      • Contact US
      • About
    Facebook X (Twitter) Instagram
    Java HelpsJava Helps
    Home » Create A New Maven Project In IntelliJ IDEA
    Apache Maven
    Apache Maven
    Maven

    Create A New Maven Project In IntelliJ IDEA

    Gobinath LoganathanBy Gobinath LoganathanNovember 29, 2022Updated:December 4, 2022No Comments4 Mins Read
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Almost all the articles in Java Helps with a Java project use Apache Maven to create the project. This article shows how to create a new Apache Maven project in IntelliJ IDEA for beginners. Before getting your hands dirty let’s get yourself familiar with some keywords used in the Apache Maven context.

    Requirements

    • Intellij IDEA
    • Apache Maven (Optional)

    Apache Maven Terms

    TermDescription
    POM/pom.xmlProject Object Model. It is an XML file that contains information about the project and configuration details used by Maven to build the project. You will find this file in the project directory.
    ArtifactThe output generated by building a Maven Project. Usually, it refers to the JAR files compiled from the source code.
    Group IdA unique identifier for your project across all projects. The naming convention follows Java’s package name rules. This means it starts with a reversed domain name you control. For example, I use com.javahelps.project as the groupId for all my projects.
    Artifact IdThe name of your package (JAR most of the time) without the version number. Recommended using lowercase letters and no strange symbols (usually lowercase words separated by hyphens).
    VersionThe package version.
    Snapshot VersionVersion ending with -SNAPSHOT indicating the built package (JAR file) is under development and not for production use. Though you can still use it for production at your own risk.
    DependencyAny library your project is depending on.
    PluginAdditional components to extend the functionality of Apache Maven.
    ArchetypeApache Maven project templates that can be used to generate a particular type of project. For example, the scala-archetype-simple archetype can be used to create Scala projects.
    Maven RepositoryA public repository hosting almost all Apache Maven dependencies (aka libraries). This is where you will find all your dependencies. The URL is: https://mvnrepository.com
    Local RepositoryTo avoid downloading the same dependencies, again and again, Apache Maven will maintain a local copy of the artifacts on your computer. Linux and Mac users can find it at ~/.m2/repository

    Creating A New Maven Project

    Step 1:
    Open IntelliJ IDEA and go to File → New → Project from the menubar or click on the “New Project” button on the welcome screen.

    Step 2:
    In the appeared dialog, enter the artifact id as the project name and select a project location to save the project. In the same dialog, select Java as the language along with your desired JDK version. Also, make sure that the Build system is set to Maven. Next, expand the Advanced Settings section and enter your Group Id. Finally, click the “Create” button.

    In the following screenshot, I am creating a new project with the Group Id: com.javahelps.helloworld and the Artifact Id: hello-world.


    Exploring The Maven Project

    The created project will have the following file structure:

    hello-world/
    ├── pom.xml
    └── src/
    ├── main/
    │ ├── java/
    │ │ └── com/
    │ │ └── javahelps/
    │ │ └── helloworld/
    │ │ └── Main.java
    │ └── resources/
    └── test/
    └── java/

    pom.xml

    The pom.xml file contains the groupId, artifactId, version, and Java version for this project. The original pom.xml file may look like the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.javahelps.helloworld</groupId>
    <artifactId>hello-world</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    </properties>

    </project>

    Suppose you want to add commons-lang3 and commons-collections4 libraries as dependencies to your project, you will have to modify the project as shown below:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.javahelps.helloworld</groupId>
    <artifactId>hello-world</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.12.0</version>
    </dependency>

    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-collections4</artifactId>
    <version>4.4</version>
    </dependency>
    </dependencies>

    </project>

    You can add any number of dependencies to your project inside the <dependencies> tag. After modifying the pom.xml, make sure to load the changes into IntelliJ IDEA by clicking the popup that appears in the top right corner. Otherwise, right-click on the project and select Maven → Reload Project.

    Synchronize Maven Project in IntelliJ IDEA

    Main.java

    Main.java is the main class created for your convenience. You can modify it, delete it or create new classes as you wish. Click the play button on the left side panel next to the class definition or main method to run the project from IntelliJ IDEA.

    Run a class in IntelliJ IDEA

    Maven Command Line

    Alternatively, if you have Apache Maven installed, you can also run the following commands from the terminal to build and run the Main class.

    mvn compile
    mvn exec:java -Dexec.mainClass=com.javahelps.helloworld.Main


    Running the following command will compile and package your project into a JAR file.

    mvn package

    I hope this article helped you create your first Apache Maven project in IntelliJ IDEA. If you find it useful or if you have any questions, please comment below.

    intellij maven
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    Run NiFi Cluster in Docker with SSL Enabled

    December 6, 2022

    How to Set Proxy for Maven?

    December 6, 2022

    How to Create a Fat JAR Using Maven?

    December 5, 2022

    Create Scala Project with Maven in IntelliJ IDEA

    December 4, 2022
    Don't Miss
    Configure

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    IntelliJ Idea: the famous IDE for JVM languages including Java, Scala, and Kotlin. If you…

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022

    Manage GitHub Artifact Storage Quota

    December 6, 2022
    Our Picks

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022

    Manage GitHub Artifact Storage Quota

    December 6, 2022
    About Us
    About Us

    Java Helps is the platform to share all about the Java ecosystem. All the sample code available on Java Helps articles are published under Apache 2.0 License. Readers are free to use them according to the Apache 2.0 License.

    "The world is my town; its people my kinsmen."
    -Kaṉiyan Pūngunṟanār

    Email Us: www.javahelps@gmail.com

    Our Picks

    Things To Do After Installing IntelliJ IDEA

    December 20, 2022

    How to Set Proxy for IntelliJ IDEA?

    December 20, 2022

    What is Garbage Collection?

    December 7, 2022
    New Comments

      Type above and press Enter to search. Press Esc to cancel.

      Go to mobile version