Lets create a simple application as we have seen in Tutorial -2.
Execute the following command. Ensure you have jdk bin and maven bin folders in path!
$ mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=org.grassfield.app -DartifactId=my-app
We are generating a simple project based on generate architype – a simple template. After issuing the above command, you will see a list of lines and characters are running on the screen. You will be asked some questions, just press enter!
You can see a new folder is created with your artifact id, which is ‘my-app’ here! If you browse through this folder, you will see the following.
$ ls
my-app
$ cd my-app/
$ ls
pom.xml src
$ cd src
$ ls
main test
$ cd main
$ ls
java
$ cd java
$ ls
org
$ cd org/grassfield/app/
$ ls
App.java
App.java – Created by Maven
Lets modify it now.
Here it is!
Lets see what’s written inside pom.xml
pandian@pandian-SH560:~/pandian/my-app$ cat 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>org.grassfield.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-app</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>
POM refers to junit alone as its dependency!
Now lets compile it.
$ mvn compile
Done!
Lets test it now! The following is the maven test case.
$ mvn test
Lets package it now!
$ mvn package
Console is interesting. But you love Eclipse IDE like, right? Lets create the Eclipse project structure for this artifact.
$ mvn eclipse:eclipse
Now import the java project from the location highlighted above.
Lets see how to work with Eclipse using Maven in my next post.
Related posts:








