English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Maven Build Java Project

Maven uses archetype archetype plugin to create a project. To create a simple Java application, we will use maven-archetype-quickstart plugin.

In the following example, we will create a Java application project based on maven under the C:\MVN folder.

Command format is as follows:

mvn archetype:generate"-DgroupId=com.companyname.bank"-DartifactId=consumerBanking"-DarchetypeArtifactId=maven"-archetype-quickstart"-DinteractiveMode=false"

Parameter description:

  • -DgroupId: Organization name, the reverse of the company's website + Project name

  • -DartifactId: Project name-: Module name

  • -DarchetypeArtifactId: Specify ArchetypeId, maven-archetype-quickstart, create a simple Java application

  • -DinteractiveMode: Is interactive mode used

The generated folder structure is as follows:

Description of each folder:

Folder structureDescription
consumerBankingContains src folder and pom.xml
src/main/java containsjava code files are located under the package structure (com/companyName/bank).
src/main/test containsThe test code file is located under the package structure (com/companyName/bank).
src/main/resourcesContains images / The attribute file (in the above example, we need to manually create this structure).

In C:\MVN\consumerBanking\src\main\java\com\companyname\bank In the folder, you can see an App.java file, the code is as follows:

package com.companyname.bank;
 
/**
 * Hello world!
 *
 */
public class App 
{
    public static void main(String[] args)
    {
        System.out.println("Hello World!");
    }
}

Open C:\MVN\consumerBanking\src\test\java\com\companyname\bank folder, you can see the Java test file AppTest.java.

package com.companyname.bank;
 
import.junit.framework.Test;
import.junit.framework.TestCase;
import junit.framework.TestSuite;
 
/**
 * Unit test for simple App.
 */
public class AppTest extends TestCase 
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }
 
    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }
 
    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }
}

During the subsequent development process, we only need to place the structure mentioned in the above table properly, and Maven will take care of the rest.