Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Maven Building a Java Project

Maven Building a Java Project

Maven Using Archetypes 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 maven-based java application project under the C:\MVN folder.

The command format is as follows:



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

Parameter Description:

The generated folder structure is as follows:

Description of each folder:

Folder structure Description
consumerBanking Contains the src folder and pom.xml
src/main/java contains Java code files are under the package structure (com/companyName/bank).
src/main/java test Test code files are under the package structure (com/companyName/bank).
src/main/resources Contains image / property files (in the example above, we need to create this structure manually).

in C:\MVN\consumerBanking\src\main\java\com\companyname\bank In the folder, you can see an App.java, with the following code:

App.java

package

com

.

companyname

.

bank

;

/*

*/

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.

AppTest.java

package

com

.

companyname

.

bank

;

import

junit

.

framework

.

Test

;

import

junit

.

framework

.

TestCase

;

import

junit

.

framework

.

TestSuite

;

/*

*/

public

class

AppTest

extends

TestCase

{

/*

@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

)

;

}

/*

*/

public

void

testApp

(

)

{

assertTrue

(

true

)

;

}

}

In the subsequent development process, we only need to place things according to the structure mentioned in the table above; Maven will take care of everything else for us.