Commands

Common every-day commands

Command

Description

mvn clean installClean, build and test
mvn clean install -DskipTestsDon't run tests
mvn compile
mvn package
mvn test
mvn -Ptest,verifier,all,dev-test install -Dit.test=LocalStorageTestRun a test


Project startup

Command

Description

>mvn archetype:generate

archetype: 888

version: <pick latest>

groupId: com.company.something

artifactId: AppName (will translate to the jar/war built)

version: 1.0-SNAPSHOT

package: <groupId value>


Create a new maven project. This command will setup the basic directory structure used by maven projects. You will be prompted for an a number of parameters. For groupId, input your company name or base package name for your code. For artifactId, input t=your application name.



Maven Lifecycle


Maven defines number of phases. Here are a few:

Lifecycle

Description

validate

Validates your project
compileCompiles your code
testRuns your tests
packagePackages your code
installPackages and installs to your local repository
deployWhen publishing your artifact to a public repository (Not typically used)

Dependencies

In the sample pom.xml file below we can see that we have a dependency on the junit library for the test scope. 



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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company</groupId>
  <artifactId>myApp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>myApp</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    ...
  </dependencies>
</project>

  • No labels