What is Maven – Troubleinthepeace

1. What is Maven?

Maven is a software project management and automation tool. Primarily for java programmers, but it can also be used to build and manage projects using C#, Ruby, Scala or other languages.

You are watching: What is Maven?

Maven serves the same purpose as Apache Ant, but it is based on a different concept and a different way of working. Maven supports automating the processes of initial project creation, compilation, testing, and packaging. and product deployment.Developed in Java language allows Maven to run on many different platforms: Windows, Linux and Mac OS…

2. How does Maven work?

Maven uses the concept of Project Object Model (POM) to describe building projects, dependencies, and modules.

See also: What is TPM – Total Productive Maintenance

It pre-defines targets for task declaration, compiler, packaging and order of operations so that everything goes well. In each project Maven creates a .pom file, in this file the tasks are defined. like task when running test, task when building and when running Maven will rely on these definitions to manipulate the project.

See also: What is a project – What is an investment project concept?

Example file .pom

4.0.0 com.mycompany.app my-app 1.0 junit junit 3.8.1 test

3. Why need Maven?

When a project is developed by many teams, for example, there are 2 teams participating in the project, those 2 teams are in 2 different countries, so we always need to have a contact to unify in programming. some kind of standard for everyone to follow, like in what libraries to use, the version of the library all of that is managed by Maven. For large, complex systems use Using many libraries requires continuous release, so it takes time to package (build & deploy), manage, upgrade and maintain them, and then we have Maven.

4 Install Maven

Install from Ubuntu reposite.$ sudo apt-get install mavenVerification:$ -versionApache Maven 3.0.4Maven home: /usr/share/mavenJava version: 1.7.0_09, vendor: Oracle CorporationJava home: /usr/lib/jvm/java -7-openjdk-amd64/jreDefault locale: en_US, platform encoding: UTF-8OS name: “linux”, version: “3.5.0-17-generic”, arch: “amd64”, family: “unix”

5. Initializing a Java Project with Maven

Create Project:archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false The :groupId: parameter is usually named after the organization or group that created the projectartifactId: usually taken by the abbreviation of the project.archetypeArtifactId: is the type of project that will be created, Maven provides many types of templates available for users to choose from when initializing. Result: we will get a project with the architecture like after:


7. Maven commands

Build project with maven: packageDeploy to Tomcat: tomcat:deployCreate a .project file that can be imported into eclipse: eclipse:eclipseRun unit test testClean project: clean

8. Demo

Step1: Initialize a project:

archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=falseStep2: main.java file content

package com.mycompany.app;/*** Hello world!**/public class App public static void main( String<> args ) System.out.println( “Hello World!” );

Step 3: Change .pom, add plugin to build project:

4.0.0com.mycompany.appmy-appjar1.0my-apphttp://maven.apachejunit junit 3.8.1 test org.apache.maven.plugins maven-jar-plugin 2.4 true lib/ com.mycompany.app.App Step 4: Build


About Troubleinthepeace

Troubleinthepeace specializing in synthesizing information about daily life activities

View all posts by Troubleinthepeace →

Trả lời

Email của bạn sẽ không được hiển thị công khai.