Maven Java project can be created in 2 ways:

  1. Through command line
  2. Through an IDE like eclipse, net beans, IDEA etc.

Please check the blog for setting up maven Installing maven in linux

This tutorial will explain how to create a java project using maven through command line.

Creating a project

You will need a directory to put you project contents into. So please create directory and go to there, and run the following command to create a java project, using simple archetype.

$ cd hello-world-app

$ mvn archetype:generate -DartifactId=helloworld-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

The project is created in the name of ‘artifactId’ you have passed.      You can see the project created message as :

[INFO] -----------------------------------------------------------
[INFO] -----------------------------------------------------------
[INFO] Total time: 16.824 s
[INFO] Finished at: 2014-10-30T15:02:38+01:00
[INFO] Final Memory: 18M/162M

What did I just do?

You executed the Maven goal archetype:generate, and passed in various parameters to that goal. The prefix archetype is the plugin that contains the goal. If you are familiar with Ant, you may conceive of this as similar to a task. This goal created a simple project based upon an archetype.

The folder structure will be created, that is the standard directory structure of any maven project:


Importing this project to IDE

To work further on this project, we will import this into any ide. Eclipse is used here to work on it.

So making this project ready to be imported, we will run the following command:

$ mvn eclipse:eclipse

Now this project can be imported to any IDE.

Eclipse IDE it can be done as follows:

Open-> File-> Import -> Maven -> Import existing maven projects

then import. Click Finish.


Please look at the pom.xml. It is simple and it has only one dependency junit. Because our hello world app requires only junit external dependency to do the test.

<project xmlns="" xmlns:xsi=""

If you look at the App.Java, a simple add() method is added to perform addition of 2 numbers.


* Hello world!
public class App
public static void main( String[] args )
System.out.println( "Hello World!" );

public int add(int param1, int param2){
return param1 + param2;

So we write unit test case to cover that as follows in class.

* Unit test for simple App.
public class AppTest
extends TestCase
* Rigourous Test 🙂
public void testAdd()
assertEquals( 3, new App().add(1, 2) );

Build the project

$ mvn package

The command line will print out various actions, and end with the following:

[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.616 s
[INFO] Finished at: 2016-10-30T16:05:46+01:00
[INFO] Final Memory: 20M/146M

Unlike the first command executed (archetype:generate) you may notice the second is simply a single word – package. Rather than a goal, this is a phase. A phase is a step in the build lifecycle, which is an ordered sequence of phases. When a phase is given, Maven will execute every phase in the sequence up to and including the one defined.

For example, if we execute the compile phase, the phases that actually get executed are:


You may test the newly compiled and packaged JAR with the following command:

$ java -cp target/helloworld-app-1.0-SNAPSHOT.jar

Which will print

 Hello World!

Installing apache maven in linux(Ubuntu).

Make sure you have java installed already in you machine. You could check it running following command: java -version

You should see something like this:

$ java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Apache maven:

Maven is a project and build management tool which is working based on the concept called POM-Project Object Model. Maven can manage a project’s build, reporting and documentation from a central piece of information.

Maven provides developers a complete build lifecycle framework. Development teams can automate the project’s build infrastructure in less time as Maven uses a standard directory layout(see maven project directory structure.) and a default build lifecycle.

In case of multiple development teams environment, Maven can set-up the way to work as per standards in a very short time. As most of the project setups are simple and reusable, Maven makes life of developer easy while creating reports, checks, build and testing automation setups.

Maven provides developers ways to manage following:

Builds, Documentation, Reporting, Dependencies, SCMs, Releases, Distribution, mailing list

To summarize, Maven simplifies and standardizes the project build process.

To install maven in ubuntu follow the below steps:

$ sudo apt-get install maven

It will install latest maven, check the installation by running the following command:

$ mvn -version
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_101, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-45-generic", arch: "amd64", family: "unix"

You can also install by downloading the zip file from maven website and do it manually, in that case, you will have to set the environmental variable m2_home manually.

Please follow the below steps:

Visit to and check what is the latest tar.gz file.
When you want e.g. apache-maven-3.2.1-bin.tar.gz, from the command line; you should be able to simply do:


And then proceed to install it.
Run command above from the dir you want to extract maven to (e.g. /usr/local/apache-maven)
run the following to extract the tar:
tar xvf apache-maven-3.2.1-bin.tar.gz
Next add the env varibles such as
export M2_HOME=/usr/local/apache-maven/apache-maven-3.2.1
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

Please verify the installation as:
mvn -version

There are various ways to generate XML files in java. One of the easiest ways is to use DOM DocumentBuilderFactory.

DOM provides easy APIs to create XML. You will have to create DocumentBuilder from DocumentBuilderFactory, then add all the nodes like elements, attributes, comments, text nodes.

Finally you need to transform the document in to xml using transformers(javax.xml.transform.Transformer).You can transform document to xml file or simply console output for your convenience.

The XML we need to create is “rices.xml”, it will look like below at the end:


Java program to create the above XML file:


import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.OutputKeys;

import org.w3c.dom.Attr;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class CreateXMLUsingDOM {
public static void main(String args[]){
try {
DocumentBuilderFactory theDocBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder theDocBuilder = theDocBuilderFactory.newDocumentBuilder();
Document theDoc = theDocBuilder.newDocument();
// root element
Element theRootElement = theDoc.createElement("rices");

// rice element
Element theRiceEl = theDoc.createElement("rice");
// adding attribute 'id' to 'rice' element
// setting attribute to element
Attr theAttr = theDoc.createAttribute("id");

 // Adding comment
 Comment theComment = theDoc.createComment("Rice and it's properties");		
 theRootElement.insertBefore(theComment, theRiceEl);

// name element
Element theNameEl = theDoc.createElement("name");
// adding text node

// type element
Element theTypeEl = theDoc.createElement("type");
// adding text node

// country element
Element theCountryEl = theDoc.createElement("country");
// adding text node

// days element
Element theDaysEl = theDoc.createElement("days");
// adding text node

// write the content into xml file
TransformerFactory theTransformerFactory = TransformerFactory.newInstance();
Transformer theTransformer = theTransformerFactory.newTransformer();
theTransformer.setOutputProperty("{}indent-amount", "4");
theTransformer.setOutputProperty(OutputKeys.INDENT, "yes");

DOMSource theSource = new DOMSource(theDoc);
StreamResult theResult = new StreamResult(new File("C:\\temp\\rices.xml"));
theTransformer.transform(theSource, theResult);

// Output to console for testing
StreamResult theConsoleResult = new StreamResult(System.out);
theTransformer.transform(theSource, theConsoleResult);

} catch (Exception e) {

To align the xml or console output to more readable pretty format, the following two options in the transformers are used. This will add 4 space indentation to each tag in the element.

theTransformer.setOutputProperty("{}indent-amount", "4");
theTransformer.setOutputProperty(OutputKeys.INDENT, "yes");

DOM – Document Object Model

I have developed a small standalone tool using adobe air. The tool is called "Budgeting tool". This tool can be used to store day to day spendings for groceries or milk or whatever we spend on daily basis. You can make an entry daily. you can also see the reports for your spending and all signed in user's as well.

I got the idea from our room. actually we are a few friends staying together. we use to buy milk packs curd , vegetables and groceries for our room,and we will make a note of it in a notepad. End of the month we will calculate the spendings and individual contribution on groceries and we will calculate how much each person has to pay.

I have developed the tool to do this manual calculation. As this is developed using adobe air, look and feel is awesome compare to old desktop application development technologies.

I have posted a few screenshots of my application. Please feel free to ask me , if you need the tool for your room/ house , when u r in such a need of application.

I will come up with new useful blogs on RIA, as this is my first blog, I will update this with technical details soon. At present this doesn't contain any technical information about Adobe AIR and flex.

Securing your web application is equally important as developing quality applications.An application is comprised of lot of resources which is available for their callers/users.

Security is an important aspect of applications that transport sensitive data over the internet.
It is important to protect the resources from being attacked/illegally accessed.
Basically illegitimate access to the resources of the application have to be stopped/rejected.

There are two main concerns in securing web applications and that need to be addressed:

  • Preventing unauthorised users from gaining access to protected content.
  • Preventing protected content from being read while it is being transmitted.

We will see some terms and we will jump back to the above 2 concerns.


Let us assume , we have a house(web application), it has lock and its locked(secured). We need key to open the house.

This is exactly called ‘Authentication’. You validate(authenticate) yourself with a key to get into the house.
This is the very first step to get into the house.

In software terms
“Determining whether a user is who he or she claims to be.” Mechanisms such as username/password, smart cards, and Public Key Infrastructure (PKI) can be used to assure authentication.

Authorization or Access Control:

Once you enter into the house,you are allowed to use/touch/access certain things in the house(TV, a room) ,

and you are not allowed to access/touch/use some items(example, the locked table drawer, another room).
This is called ‘access control or authorization’.

In software terms:
Ensures that an authenticated entity can access only those services they are allowed to access. Access control lists are used to implement this.

The above two terms (authentication and authorization or access control) are used to address the #1 concern “Preventing unauthorized users from gaining access to protected content.”

#2 concern, “Protecting data while it is in transit“, typically involves using Transport Layer Security (TLS), or its predecessor, Secure Sockets Layer (SSL), in order to encrypt any data communicated between the client and server.

Web applications are there to serve their callers through either ‘http://’ or ‘https://’ protocol.

What is ‘http’?
Short for Hyper Text Transfer Protocol, HTTP is the underlying protocol used by the World Wide Web.
HTTP defines how messages are formatted and transmitted, and what actions Web servers and browsers should take in response to various commands.
For example, when you enter a URL in your browser, this actually sends an HTTP command to the Web server directing it to fetch and transmit the requested Web page.

What is ‘https‘?
Using HTTPS, the computers agree on a “code” between them, and then they scramble the messages using that “code” so that no one in between can read them. This keeps your information safe from hackers. They use the “code” on a Secure Sockets Layer (SSL), sometimes called Transport Layer Security (TLS) to send the information back and forth.

Common Security Terminologies

The most common security processes are authentication, authorization, realm assignment, and role mapping. The following sections define this terminology.

Authentication verifies the user. For example, the user may enter a username and password in a web browser, and if those credentials match the permanent profile stored in the active realm, the user is authenticated. The user is associated with a security identity for the remainder of the session.

Authorisation permits a user to perform the desired operations, after being authenticated. For example, a human resources application may authorize managers to view personal employee information for all employees, but allow employees to only view their own personal information.

A realm, also called a security policy domain or security domain in the J2EE specification, is a scope over which a common security policy is defined and enforced by the security administrator of the security service. Supported realms in Sun Java System Application Server are file, ldap, certificate, and solaris. For information about how to configure a realm, see Realm Configuration.

Role Mapping
A client may be defined in terms of a security role. For example, a company might use its employee database to generate both a company wide phone book application and to generate payroll information. Obviously, while all employees might have access to phone numbers and email addresses, only some employees would have access to the salary information. Employees with the right to view or change salaries might be defined as having a special security role.

A role is different from a user group in that a role defines a function in an application, while a group is a set of users who are related in some way. For example, members of the groups astronauts, scientists, and politicians all fit into the role of SpaceShuttlePassenger.