Maven "Hello World" 

Joined:
08/13/2009
Posts:
172

August 13, 2009 04:18:26    Last update: August 13, 2009 04:18:26
To start a simple "Hello World" project in maven, enter:
mvn archetype:create -DgroupId=com.example -DartifactId=hello-world

in the command line. It will take a while for Maven to run. But eventually it will create the standard Maven directory structure with a "Hello World" app and a fake JUnit test.

Enter
mvn package

will build the simple App into a jar under the target directory.

Run the resulting App:
C:\maven\hello-world>java -cp target\hello-world-1.0-SNAPSHOT.jar com.example.App
Hello World!


This is the generated pom:
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>hello-world</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>hello-world</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>
Share |
| Comment  | Tags
2 comments