Installing Apache Maven


export M2_HOME=path to Maven
export PATH=$PATH:$M2_HOME
  • . ./.profile
  • mvn –version

Create a Sample Project from the Command Line

  • CD to your Development Root folder
  • mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

This creates the following directory structure:

my-app
+- pom.xml
+- src
   +- main
   |  +- java
   |     +- com.mycompany.app
   |         +- App.java
   +- test
      +- java
         +- com.mycompany.app
            +- AppTest.java

Build the Project

  • cd my-app
  • mvn package

This creates the following directory structure within my-app

my-app
+- main ...
+- test ...
+- target
   +- classes
   |  +- com.mycompany.app
   |     +- App.class
   +- maven-archiver
   |  +- pom.properties
   +- my-app-1.0-SNAPSHOT.jar
   +- surefire
   +- surefire-reports
   |  +- com.mycompany.app
   |  |  +- AppTest.txt
   |  +- TEST-com.mycompany.app
   |     +- AppTest.xml
   +- test-classes
      +- com.mycompany.app
         +- AppTest.class

Run the Project

  • java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
  • prints Hello World!

 

For more information check out Maven in 5 minutes

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s