目次
Apache Maven Reviews
Apache Maven is a software project management and comprehension tool that make it easy for developers to develop their systems.
you learn a few of the main concepts. Each project contains a file called a POM (Project Object Model), Maven can manage a project’s build, reporting and documentation from a central piece of information. Maven is a build automation tool for Java projects.
Installation Maven
Maven is a Java tool, so you must have Java installed in order to proceed.( JDK version 1.5)
1 |
mvn -v |
1 2 3 4 5 6 |
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100) Maven home: D:\apache-maven-3.0.5\bin\.. Java version: 1.6.0_25, vendor: Sun Microsystems Inc. Java home: C:\Program Files\Java\jdk1.6.0_25\jre Default locale: nl_NL, platform encoding: Cp1252 OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows" |
Creating a Project
1 |
mvn archetype:generate -DgroupId=com.javapapers.sample -DartifactId=first-mavenapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false |
The src/main/java directory contains the project source code, the src/test/java directory contains the test source, and the pom.xml file is the project’s Project Object Model, or POM.
POM.xml
This is equivalent to the ANT build xml file. POM is the fundamental unit of work in Maven. It is an XML file that contains the configuration settings for a project build.
|
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<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>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1.0-SNAPSHOT</version> <!-- packaging>jar</packaging --> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> </project> |
Dependencies
There is an element available for declaring dependencies in project pom.xml This is used to define the dependencies that will be used by the project. Maven will look for these dependencies when executing in the local maven repository. If not found, then Maven will download those dependencies from the remote repository and store it in the local maven repository.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.opencsv</groupId> <artifactId>opencsv</artifactId> <version>3.9</version> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.4.1212</version> </dependency> </dependencies> |
Plugins
All the execution in Maven is done by plugins. A plugin is mapped to a phase and executed as part of it. A phase is mapped to multiple goals. Those goals are executed by a plugin. We can directly invoke a specific goal while Maven execution. A plugin configuration can be modified using the plugin declaration.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<build> <finalName>springexcelexport</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.16</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </build> |
Maven Build Lifecycle
Maven defines and follows conventions. Right from the project structure to building steps, Maven provides conventions to follow. If we follow those conventions, with minimal configuration we can easily get the build job done.
There are three built-in build life cycle ‘clean’, ‘default’ and ‘site’. A life cycle has multiple phases.
This will create a sample Maven project skeleton using we can start building the application.We will get a a pom.xml and let us use that to build the newly created Maven project. Go inside the newly created Maven project root and execute the command
1 |
mvn package |
The command line will print out various actions, and end with the following:
1 2 3 4 5 6 7 8 9 10 |
... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2 seconds [INFO] Finished at: Thu Jul 10 19:04:48 CEST 2011 [INFO] Final Memory: 3M/6M [INFO] ------------------------------------------------------------------------ |
- Simple AWS DeepRacer Reward Function Using Waypoints - 2023-12-19
- Restrict S3 Bucket Access from Specified Resource - 2023-12-16
- Expand Amazon EBS Volume on EC2 Instance without Downtime - 2023-09-28
- Monitor OpenSearch Status On EC2 with CloudWatch Alarm - 2023-07-02
- Tokyo’s Coworking Space Hidden Gem: AWS Startup Loft Tokyo - 2023-05-24