1. 程式人生 > >linux能搭建maven倉庫

linux能搭建maven倉庫

對Linux及Maven都不熟悉,在網上折騰,然後總結如下:
一.搭建倉庫(JDK required):
linux platform, IP:192.168.2.99
1.download apache-maven-x.x.x-bin.tar.gz
2.download nexus-oss-webapp-x.x.x.x-bundle.tar.gz
3.tar -zxvf apache-maven-x.x.x-bin.tar.gz -C /usr/java/
4.add enviroment variable:
a. vi /etc/profile;
b. append 'MAVEN_HOME=/usr/java/***'
c. append 'PATH=${PATH}:${MAVEN_HOME}/bin'
d. append 'export MAVEN_HOME PATH'
e. source /etc/profile
5.tar -zxvf nexus-oss-webapp-x.x.x.x-bundle.tar.gz -C /usr/java/
6.startup(shutdown) nexus:
a. cd nexus/nexus-oss-webapp-1.9.0.2/bin/jsw/linux-x86-32/
b. ./nexus start(stop)
7.test:
http://localhost:8081/nexus

ok, login as admin/admin123 (default)

二、使用Mavan倉庫:
windows platform, IP:192.168.2.3
1.download and setup apache-maven-x.x.x-bin.zip (D:/maven)
2.add enviroment variable:
new MAVEN_HOME:D:/maven
add to path:%MAVEN_HOME%/bin
test:mvn -version, ok
3.open the file "settings.xml " under the folder "d:/maven/conf"
add the next chars into the file:
<localRepository>C:/.m2/repository</localRepository>
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>

<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>linux-nexus</name>
<url>
http://192.168.2.99:8081/nexus/content/groups/public
</url>
<id>nexus</id>
</mirror>
</mirrors>

<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>nexus</id>
<url>http://192.168.2.99:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>
http://192.168.2.99:8081/nexus/content/groups/public
</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
save, ok.
4.mkdir "d:/workspace"
5.mvn archetype:generate
6.choose the default selection(16)
7.input some informations(the project name:helloworld)
8.ok, look the dir "D:/workspace", there is a folder "helloworld"
9.open the file "pom.xml " under "helloworld", add some dependencies, example:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6.SEC02</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.2.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
10.run the command "mvn install " under "helloword", then, it will download some jars and poms
into "C:/.m2/repository"(default) from 192.168.2.99.
11.convert this maven project to eclipse project:
under the folder "helloworld", run "mvn eclipse:eclipse ".
說明:192.168.2.99是虛擬機器中Linux的IP,192.168.2.3是虛擬機器中Win7的IP。