Skip to main content

1st Program in Maven @ Ubuntu

Maven
What is Maven?
It is a
Build tool – building a code in a development environment
Project management tool – it helps to generate reports, helps in the dependency management, etc.

Maven as a Build tool.

Why we are using Maven?
To reduce the common problems and activities which are needed, when we are developing applications.
1. Multiple jars – Program may contain one/many frameworks and frameworks are need to include it all the required “jar”. “jar” are need to available in compile time, need to bundle them in the distribution. (We can miss something/ we don’t know what is jar?)
2. Dependencies and versions – a jar can depend on another jar, so we have need to make sure that all my dependencies are closed and make sure that I have supplied all the dependencies. Dependencies could differ bases on the versions.
3. Project structure – Proper structure for the application. (E.g. Directories, libraries , etc.)
4. Building, publishing and deploying

Repositories – helps Maven to overcome the above mention common problem and activities.

How to install Maven? Click Here.


Make a Simple Maven Application.

Steps:
1. Make a directory [mkdir myapp]
2. Move into the directory [cd myapp/]
3. To download Maven Repositories from online [mvn archetype:generate]
Note – Make sure that you are connected to internet
//this command will download all the Maven plugging.
Choose a number ? Go with the default number what is it showing. (press enter)
What is archetype? It is a model how we want our project. (predefined)
Choose a version number? 6 & enter
Define value for property ‘groupId’? org.apache.maven //similar to the Package
Define value for property ‘artifactId’? MavenSampleApp //similar to class name – name for the complete application
Define value for property ‘version’: 1.0.SNAPSHOT? Use as it as default NOW
Define value for property ‘package’: org.apache.maven:? Use the default selected GroupId
Ask conformation for the inputs what we did now. Press ‘y’ and enter.
FINISHED

It will create a directory named ‘MavenSampleApp’ as we created. And inside to that directory there is a ‘src’ directory and a ‘pom.xml’ file.

Example: Information about the application - ‘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.apache.maven</groupId>                 //entries we have entered//
  <artifactId>MavenSampleApp</artifactId>            //entries we have entered//
  <version>1.0-SNAPSHOT</version>                     //entries we have entered//
  <packaging>jar</packaging>                                  //entries we have entered// application we are writing will be build and package as a jar.

  <name>MavenSampleApp</name>             //name of the application. Differ from artifactId. (Application call by this name but saving this compiled application in the repository artifactId will be use) //
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>                                //this the place where Maven going to play
    <dependency>
      <groupId>junit</groupId>           //this project is depend on the junit
      <artifactId>junit</artifactId>
      <version>3.8.1</version> //junit version
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Compile the Maven Application

Default: There will be a Java class with Main Method having the out put of “Hello World” (selected archetype – create this automatically)

Steps
1. Go to the directory which has ‘pom.xml’
2. [mvn compile]
//downloading all the relative dependencies mentioned in the ‘pom.xml’ + compile the Java class in the application directory. (all the classes in the ‘src’ folder compiled in a single command)
3. [mvn package]
//it will package into a jar file + some downloads of plugging 
After this done you can see a build jar inside the ‘target’ directory which is inside our applicatio directory.
Example: [INFO] Building jar: /home/benjamineubuntu/myapp/MavenSampleApp/target/MavenSampleApp-1.0-SNAPSHOT.jar
4. Execution [java -cp target/MavenSampleApp-1.0-SNAPSHOT.jar org.apache.maven.APP]
Note : Make sure you are inside the directory where the ‘pom.xml’ file is saved.
//java -cp target/MavenSampleApp-1.0-SNAPSHOT.jar [artifactId][.][Java class wants to run (without ‘.java’)]
5. Display output as ‘Hello World!’

What maven has done up to that?


©IT Today


Comments

Popular posts from this blog

What is Google Hacking?

As an ethical hacker we have need to follow some general steps to be a good ethical hacker. Such that steps/stages can be listed as follows. But these steps are not a defined one. We can change them according to our needs. 1    . Reconnaissance – Gathering the information which are having the security vulnerability. 2   . Scanning - Examine/explore a target machine/network for the vulnerability that can be make use to go inside. 3    .Gaining Access – After scanning process make use of the vulnerability and attempt to move inside to the system to exploit. 4    . Maintaining Access – After moved into the machine/network hacker needs to make some backdoor to gain the access again. 5    . Clearing Tracks (unethical) – Clearing the traces of all the activities what they done in their hacking process. 6    . Reporting – End of the ethical hacking process in order to make some notes on the findings, things done in the hacking...

Bandit Wargame – Documentation

Basically wargames are providing the basic knowledge on the security concepts. It is a game that contain many tricks to break the borders to gain the access especially passwords (commands are mostly on the Linux CLI). You can find many wargames through the Internet and they are very interest and fun full too. “Bandit” is also a wargame which is for the beginners. You all can access that through the link given bellow. And this article is an document for this game. I have used Ubuntu as the operating system. Bandit – Clickhere . Level 0: Case study → Clickhere Here we have need to connect the host through the SSH (secure socket shell) server. The informations are provided as follows. Host name: bandit.labs.overthewire.org Port No: 2220 User name: bandit0 Password: bandti0 There are many ways to connect through the SSH server. Method 1: Download and run the “PuTTY SSH client”. ( https://the.earth.li/~...

Introduction to OAuth

What is OAuth? OAuth is a protocol that allows distinct parties to share information and resources in a secure and reliable manner. OAuth needs to consider the 2 concept to provide the informations in secure and reliable manner. They are authentication and authorization. Authentication -> Validating the person/system who need the information Authorization -> After authentication what action can be performed by the person/system. By maintaining this 2 concept OAuth is providing federated identity and delegated identity. Federated identity -> User can use his/her one application account to login another application. [Example: If a user having Facebook account then he can login Instagram with the same login as Facebook] Delegated identity -> One service can access another service resources. [Example: When creating a Facebook account with eMail address that will suggest the contacts in the eMail to add as friends] Without OAuth With OAuth User ...