Installation
- Download from Maven.
- Unzip and config path.
Maven configuration
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>
- remote repo
Project control
Make pom.xml file in root dir of porject.
1234567<?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
1234567package nan.learnjava.testmaven;public class HelloMaven {public static void main(String[] args) {System.out.println("Hello Maven!");}}Compile and run
123$> mvn clean compile // compile$> mvn clean package // package jar$> java -cp testmaven-1.0.0.jar nan.learnjava.testmaven.HelloMaven // run
Private Maven Server
NEXUS
- Download nexus-xxx-bundel.zip from NEXUS.
- Unzip and set path env.
Install service
123$> nexus install // install nexus service$> nexus start // start service$> nexus restart // restart serviceOpen in browser
Web site: http://localhost:8081/nexus
Config of nexus
Nexus repository path
Edit file ${NEXUS_HOME}/conf/nexus.properties12applicaton-port=8081 #default portnexus-work=${bundleBasedir}/../sonatype-work/nexus #default repository pathLog in
username: admin
password: admin123- Update index
Repositories –> Central –> Configuration –> Download Remote Indexes –> true
Central –> Repair Index
- Config of Maven
- Copy ${M2_HOME}/conf/settings.xml to ${HOME}/.m2/
- Edit settings.xml 123456789101112131415161718192021222324252627282930313233343536373839404142434445<!--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
- Config
Preference –> Maven –> User Setting –> Global Settings –> User Settings - New Project
New –> Project… –> Maven –> Maven Project –> Location –> Next –> … ..
Input Group Id, Artifact Id, Version, Package - Add dependencies
Edit pom.xml file, add dependency.12345<dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>2.7.4</version></dependency>