美文网首页
Maven for the rookies

Maven for the rookies

作者: ElliotG | 来源:发表于2018-07-22 15:15 被阅读0次
  1. Download & Install

Apache Maven

image.png

setup maven home

export MAVEN_HOME=/usr/local/apache-maven-3.5.3
export PATH=PATH:MAVEN_HOME/bin

check install

mvn -version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)
Maven home: /usr/local/apache-maven-3.5.3
Java version: 1.8.0_152, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents/Home/jre

setup in IDE

IntelliJ IDEA

image.png

Eclipse

image.png image.png

Create maven project

image.png image.png image.png image.png
  1. Project Object Model

Any Maven project must have a pom.xml file. POM is the Maven project descriptor,

just like the web.xml file in your Java EE web application or the build.xml file

in your Ant project

image.png
  1. Repositories

The Maven central is the only repository defined under the repositories section.
It will be inherited by all the Maven application modules. Maven uses the repositories
defined under the repositories section to download all the dependent artifacts
during a Maven build. The following code snippet shows the configuration block
in pom.xml, which is used to define repositories:

<repositories> 
  <repository> 
    <id>central</id>  
    <name>Central Repository</name>  
    <url>http://repo.maven.apache.org/maven2</url>  
    <layout>default</layout>  
    <snapshots> 
      <enabled>false</enabled> 
    </snapshots> 
  </repository> 
</repositories>
  1. Plugin repositories

Plugin repositories define where to find Maven plugins. We'll be discussing about
Maven plugins in Chapter 5, Maven Plugins. The following code snippet shows the
configuration related to plugin repositories:

<?xml version="1.0" encoding="utf-8"?>

<pluginRepositories> 
  <pluginRepository> 
    <id>central</id>  
    <name>Central Repository</name>  
    <url>http://repo.maven.apache.org/maven2</url>  
    <layout>default</layout>  
    <snapshots> 
      <enabled>false</enabled> 
    </snapshots>  
    <releases> 
      <updatePolicy>never</updatePolicy> 
    </releases> 
  </pluginRepository> 
</pluginRepositories>
  1. Build

The build configuration section includes all the information required to build
a project:

<?xml version="1.0" encoding="utf-8"?>

<build> 
  <directory>${project.basedir}/target</directory>  
  <outputDirectory>${project.build.directory}/classes</outputDirectory>  
  <finalName>${project.artifactId}-${project.version}</finalName>  
  <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>  
  <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>  
  <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory>  
  <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>  
  <resources> 
    <resource> 
      <directory>${project.basedir}/src/main/resources</directory> 
    </resource> 
  </resources>  
  <testResources> 
    <testResource> 
      <directory>${project.basedir}/src/test/resources</directory> 
    </testResource> 
  </testResources>  
  <pluginManagement> 
    <plugins> 
      <plugin> 
        <artifactId>maven-antrun-plugin</artifactId>  
        <version>1.3</version> 
      </plugin>  
      <plugin> 
        <artifactId>maven-assembly-plugin</artifactId>  
        <version>2.2-beta-5</version> 
      </plugin>  
      <plugin> 
        <artifactId>maven-dependency-plugin</artifactId>  
        <version>2.8</version> 
      </plugin>  
      <plugin> 
        <artifactId>maven-release-plugin</artifactId>  
        <version>2.3.2</version> 
      </plugin> 
    </plugins> 
  </pluginManagement> 
</build>

相关文章

网友评论

      本文标题:Maven for the rookies

      本文链接:https://www.haomeiwen.com/subject/ayslmftx.html