Create Maven Project Manually

Q

How to create a Maven project manually? I don't want to use any "archetype" project template.

✍: FYIcenter.com

A

You can follow these steps to create a Maven project manually:

1. Prepare your project required information:

  • Project code name - Required: The "artifactId" value in pom.xml. It identifies your project in your project group.
  • Project group name - Required: The "groupId" value in pom.xml. It identifies your project group. If you want to publish your project on the Internet, it needs to be unique worldwide. For example, you can use your domain name in reverse order, like com.fyicenter.jar.
  • Project current version - Required: The "version" value in pom.xml.
  • Project display name - Optional: The "name" value in pom.xml. It is used as the display name for your project.
  • Project Website URL - Optional: The "url" value in pom.xml. It is used as the display name for your project.
  • JDK version of source code - Required: The "maven.compiler.source" in pom.xml. It identifies the JDK version you are planning to use in your Java source code.
  • JDK version of target code - Required: The "maven.compiler.target" value in pom.xml. It identifies the JDK version you are planning to support in compile class files.
  • Third party JAR files required - Optional: The "dependencies" value in pom.xml. This lists all third party JAR files that are required to support your Java code.

2. Create a project directory like C:\fyicenter\abo.

C:\fyicenter>mkdir abo
C:\fyicenter>cd abo

3. Create the pom.xml file at .\pom.xml:

C:\fyicenter\abo>type pom.xml

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fyicenter</groupId>
  <artifactId>abo</artifactId>
  <packaging>jar</packaging>
  <version>1.0</version>
  <name>Apple, Banana and Orange</name>
  <url>http://jar.fyicenter.com</url>
  
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  
  <dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-collections4</artifactId>
        <version>4.2</version>
    </dependency>
  </dependencies>
</project>

4. Create the Java source code in .\src\main\java:

C:\fyicenter\abo>type src\main\java\com\fyicenter\TreeListExample.java

package com.fyicenter;

/**
 * Apple, Banana and Orange
 * Copyright (c) 2016-2018 FYIcenter.com
 *
 */

import java.util.List;
import org.apache.commons.collections4.list.TreeList;

// Example of using the TreeListExample class
public class TreeListExample {
   public static void main(String[] args) throws Exception {

      // Create some objects
      String apple = "Apple";
      String orange = "Orange";
      String banana = "Banana";

      // Create a TreeList list
      List<String> list = new TreeList<String>();
      
      // insert objects into the list from the beginning position
      list.add(0, apple);
      list.add(0, orange);
      list.add(0, apple);
      list.add(0, orange);
      list.add(0, apple);
      list.add(0, banana);

      // loop through the set as a list
      for (int i=0; i<list.size(); i++) {
         String obj = list.get(i);
         System.out.println(i+": " + obj);
      }
   }
}

The Maven project is ready.

 

abo-1.0.jar - Maven Test Project Target

\users\*\.m2 - Maven Local Repository

Using Apache Maven

⇑⇑ FAQ for Apache Maven

2018-10-31, 160👍, 0💬