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...

'OpenID Connect' Client App Creation on Auth0

If we are going to use OIDC (OpenID Connect), we have need to know the definitions of OAuth and OIDC. Because OAuth is for authorization and OIDC is on top of OAuth to provide authentication. So, OIDC is providing authorization and authentication.   What is OAuth? The OAuth 2.0 authorization framework enables third-party applications to obtain limited access to a web service. [To see more on OAuth itwithcs.blogspot.com: Click here ] What is OpenID Connect? OpenID Connect is a simple identity layer on top of the OAuth 2.0 protocol. It allows Clients to verify the identity of the End-User based on the authentication performed by an Authorization Server, as well as to obtain basic profile information about the End-User in an interoperable and REST-like manner. It uses simple JSON Web Tokens (JWT), which you can obtain using flows conforming to the OAuth 2.0 specifications. What are Identity Servers? Identity server are the core part of any identity and access control i...