hadoop-7

Maven introduction.

Installation

  1. Download from Maven.
  2. Unzip and config path.

Maven configuration

  1. Change repository
    Edit ${M2_HOME}/conf/settings.xml

    • remote repo
      <mirror>
      <profile>
    • Local repo
      Default repo is ${USER_HOME}/.m2/repository.
      1
      <localRepository>/path/to/local/repo</localRepository>
  2. Project control

    • Make pom.xml file in root dir of porject.

      1
      2
      3
      4
      5
      6
      7
      <?xml version="1.0">
      <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>nan.learnjava</groupId>
      <artifactId>testmaven</artifactId>
      <version>1.0.0</version>
      </project>
    • Make dirs nan/learnjava/testmaven.

    • Create java source file HelloMaven.java

      1
      2
      3
      4
      5
      6
      7
      package nan.learnjava.testmaven;
      public class HelloMaven {
      public static void main(String[] args) {
      System.out.println("Hello Maven!");
      }
      }
    • Compile and run

      1
      2
      3
      $> mvn clean compile // compile
      $> mvn clean package // package jar
      $> java -cp testmaven-1.0.0.jar nan.learnjava.testmaven.HelloMaven // run

Private Maven Server

  1. NEXUS

    • Download nexus-xxx-bundel.zip from NEXUS.
    • Unzip and set path env.
    • Install service

      1
      2
      3
      $> nexus install // install nexus service
      $> nexus start // start service
      $> nexus restart // restart service
    • Open in browser
      Web site: http://localhost:8081/nexus

  2. Config of nexus

    • Nexus repository path
      Edit file ${NEXUS_HOME}/conf/nexus.properties

      1
      2
      applicaton-port=8081 #default port
      nexus-work=${bundleBasedir}/../sonatype-work/nexus #default repository path
    • Log in
      username: admin
      password: admin123

    • Update index
      Repositories –> Central –> Configuration –> Download Remote Indexes –> true
      Central –> Repair Index
  3. Config of Maven
    • Copy ${M2_HOME}/conf/settings.xml to ${HOME}/.m2/
    • Edit settings.xml
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      <!--localRepository-->
      <localRepository>D:/MyApps/mvn-local-repo</localRepository>
      <!--mirror-->
      <mirrors>
      <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>nexus repo for maven.</name>
      <url>http://localhost:8081/nexus/content/groups/public</url>
      </mirror>
      </mirrors>
      <!--profile-->
      <profiles>
      <profile>
      <id>nexus</id>
      <repositories>
      <repository>
      <id>central</id>
      <name>central repos from nexus</name>
      <url>http://central</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
      </repository>
      </repositories>
      <pluginRepositories>
      <pluginRepository>
      <id>central</id>
      <url>http://central</url>
      <releases>
      <enabled>true</enabled>
      </releases>
      <snapshots>
      <enabled>true</enabled>
      </snapshots>
      </pluginRepository>
      </pluginRepositories>
      </profile>
      </profiels>
      <!--active-->
      <activeProfiles>
      <activeProfile>nexus</activeProfile>
      </activeProfiles>

Archetype

1
$> mvn archetype:generate -DarchetypeCatalog=internal

Maven for Eclipse

  1. Config
    Preference –> Maven –> User Setting –> Global Settings –> User Settings
  2. New Project
    New –> Project… –> Maven –> Maven Project –> Location –> Next –> ..
    Input Group Id, Artifact Id, Version, Package
  3. Add dependencies
    Edit pom.xml file, add dependency.
    1
    2
    3
    4
    5
    <dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-client</artifactId>
    <version>2.7.4</version>
    </dependency>