Kohei Nozaki's blog 

Memo of useful commands


Posted on Monday Feb 24, 2014 at 10:53AM in Technology


Environment

  • Apache Maven 3.1.1

Common goals

clean

  • Delete everything at target directory

compile

  • Compile sources to class files

test

  • Run JUnit test classes

package

  • Make the JAR file or WAR file

install

  • It does “package” goal and install the package to local repository so that other Maven project can reference it.

Execute Main class

mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main -Dexec.args="70112"

Show dependencies

Command

mvn dependency:resolve

What will we got

[INFO] The following files have been resolved:
[INFO]    com.ibm.icu:icu4j:jar:2.6.1:compile
[INFO]    xml-apis:xml-apis:jar:1.0.b2:compile
[INFO]    xerces:xmlParserAPIs:jar:2.6.2:compile
[INFO]    oro:oro:jar:2.0.8:compile
[INFO]    log4j:log4j:jar:1.2.14:compile
[INFO]    velocity:velocity:jar:1.5:compile
[INFO]    dom4j:dom4j:jar:1.6.1:compile
[INFO]    commons-lang:commons-lang:jar:2.1:compile
[INFO]    xerces:xercesImpl:jar:2.6.2:compile
[INFO]    commons-collections:commons-collections:jar:3.1:compile
[INFO]    junit:junit:jar:3.8.1:test
[INFO]    jdom:jdom:jar:1.0:compile
[INFO]    xalan:xalan:jar:2.6.0:compile
[INFO]    jaxen:jaxen:jar:1.1.1:compile
[INFO]    commons-io:commons-io:jar:1.3.2:test
[INFO]    xom:xom:jar:1.0:compile

Show dependencies in tree style

Command

mvn dependency:tree

What will we got

[INFO] org.sonatype.mavenbook.custom:simple-weather:jar:0.8-SNAPSHOT
[INFO] +- log4j:log4j:jar:1.2.14:compile
[INFO] +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- jaxen:jaxen:jar:1.1.1:compile
[INFO] |  +- jdom:jdom:jar:1.0:compile
[INFO] |  +- xerces:xercesImpl:jar:2.6.2:compile
[INFO] |  \- xom:xom:jar:1.0:compile
[INFO] |     +- xerces:xmlParserAPIs:jar:2.6.2:compile
[INFO] |     +- xalan:xalan:jar:2.6.0:compile
[INFO] |     \- com.ibm.icu:icu4j:jar:2.6.1:compile
[INFO] +- velocity:velocity:jar:1.5:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.1:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.1:compile
[INFO] |  \- oro:oro:jar:2.0.8:compile
[INFO] +- commons-io:commons-io:jar:1.3.2:test
[INFO] \- junit:junit:jar:3.8.1:test

Verbose Output

Command

mvn install -X

What will we got

  • It outputs tons of verbose information, such as why each jars are included or excluded.

How to skipping unit tests

mvn install -Dmaven.test.skip=true

Show description of a plugin

mvn help:describe -Dplugin=exec -Dfull

Create a jar with dependencies

mvn assembly:attached
  • This might need additional configuration of the plugin in the pom.xml

Run Jetty and deploy the WAR

mvn jetty:run
  • This might be useful for some proto-typing of servlet or jsp.
  • This might need additional configuration of the plugin in the pom.xml

Project Hierarchy

  • Every Maven projects can have children or its parent.
  • It's useful for declare common dependencies (using dependencyManagement) or plugins (using pluginManagement).
    • Child pom.xml can omit “version” element in dependencies that are declared in dependencyManagement of the parent pom.xml

Analyze “used undeclared” or “unused declared” dependencies

mvn dependency:analyze



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed