Monday, April 12, 2010

Vanilla flavour-ed Project - using Maven

Like the "generic" flavour of yummy vanilla in foods (especiallly ice-creams), the Maven creates you "generic" project structure. The 'recipe' is hereunder:

Step1:
mvn archetype:create \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.test \
-DartifactId=VanillaProject


This creates a project "VanillaProject" with pom.xml (as below) and class App.java in package com.test & a JUnit testcase for the class.


  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4.0.0
  com.test
  VanillaProject
  jar
  1.0-SNAPSHOT
  VanillaProject
  http://maven.apache.org
 
   
      junit
      junit
      3.8.1
      test
   

 


With  Project Folder structure: 
 Step 2:
 App.java (modified with System.out.println):

package com.test;
public class App
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        if(args!=null)
        System.out.println( args[0]+"::"+args[1] );
    }


2. Run the pom.xml to compile & test
mvn install

3. This compiles to get App.class. Now, run the class file

mvn exec:java -Dexec.mainClass="com.test.App" -Dexec.args="Arg0 Arg1"

No comments:

Post a Comment