Skip to content

Maven and Your First Test

Prerequisites

For this lab, you'll need Maven installed, so follow the instructions here.

Don't install IntelliJ yet, just Maven.

Step 1: Create New Project

Create a new directory for your project and switch to make that the current directory, e.g.:

> mkdir app
> cd app

Use Maven to initialize a new project by running the following command at the command line:

So if you're in the

C:\app>

Directory, copy-n-paste this command:

 mvn archetype:generate -DgroupId=com.visa.lab -DartifactId=cvm -DarchetypeGroupId=com.thepracticaldeveloper -DarchetypeArtifactId=archetype-java-basic-tpd -DarchetypeVersion=1.0.0 -DinteractiveMode=false

You will then see a lot of output, ending (hopefully) with:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  19.134 s

Change directory to the generated project:

C:\app> cd cvm

If you do a directory listing, you'll see something like

C:\app\cvm> dir

pom.xml
src

Step 2: Build the App via Maven

Maven has a number of "goals", such as "compile", "validate", etc.

Package up the app using mvn clean package

> mvn clean package

Step 3: Running the App

> java -cp target/cvm-1.0.0-SNAPSHOT.jar com.visa.lab.App

Once you've completed the above steps, check in with the instructor to review your code.