[Maven环境的搭建]
环境说明
---------------------------
sam@linux64:~> cat /etc/issue
Welcome to SUSE Linux Enterprise Server 11 (x86_64) - Kernel \r (\l).
sam@linux64:~> uname -a
Linux linux64 2.6.27.19-5-default #1 SMP 2009-02-28 04:40:21 +0100 x86_64 x86_64 x86_64 GNU/Linux
Maven 3.0.4
http://www.fayea.com/apache-mirror/maven/maven-3/3.0.4/binaries/apache-maven-3.0.4-bin.tar.gz
Nexus 2.3.0
http://www.sonatype.org/downloads/nexus-2.3.0-04-bundle.tar.gz
安装步骤
---------------------------
1、下载解压apache-maven-3.0.4、建立软连接
sam@linux64:~/maven> pwd
/home/sam/maven
sam@linux64:~/maven> ll
total 33184
lrwxrwxrwx 1 sam users 18 Jan 22 11:09 apache-maven -> apache-maven-3.0.4
drwxr-xr-x 6 sam users 4096 Jan 22 11:09 apache-maven-3.0.4
2、配置环境 & 下载maven必要的插件
echo 'export M2_HOME=/home/sam/maven/apache-maven' >> ~/.bashrc
echo 'export PATH=$PATH:$M2_HOME/bin' >> ~/.bashrc
sam@linux64:~/maven> pwd
/home/sam/maven
sam@linux64:~/maven> vi apache-maven/conf/settings.xml
( add line <localRepository>/home/sam/maven/repo</localRepository> )
sam@linux64:~/maven> mvn help:system
sam@linux64:~/maven> ll repo/
total 40
drwxr-xr-x 3 sam users 4096 Jan 22 12:14 classworlds
drwxr-xr-x 3 sam users 4096 Jan 22 12:15 com
drwxr-xr-x 3 sam users 4096 Jan 22 12:14 commons-cli
drwxr-xr-x 3 sam users 4096 Jan 22 12:15 commons-lang
drwxr-xr-x 3 sam users 4096 Jan 22 12:15 jdom
drwxr-xr-x 3 sam users 4096 Jan 22 12:14 jtidy
drwxr-xr-x 3 sam users 4096 Jan 22 12:14 junit
drwxr-xr-x 4 sam users 4096 Jan 22 12:13 org
drwxr-xr-x 4 sam users 4096 Jan 22 12:14 plexus
drwxr-xr-x 3 sam users 4096 Jan 22 12:15 xpp3
3、下载安装Nexus 2.3.0
sam@linux64:~/maven> pwd
/home/sam/maven
sam@linux64:~/maven> tar xzvf nexus-2.3.0-04-bundle.tar.gz
sam@linux64:~/maven> ln -s nexus-2.3.0-04 nexus
sam@linux64:~/maven> echo 'export NEXUS_HOME=/home/sam/maven/nexus' >> ~/.bashrc
sam@linux64:~/maven> echo 'export CLASSPATH=$CLASSPATH:$NEXUS_HOME/lib' >> ~/.bashrc
sam@linux64:~/maven/nexus/bin> pwd
/home/sam/maven/nexus/bin
sam@linux64:~/maven/nexus/bin> ./nexus start
Starting Nexus OSS...
Started Nexus OSS.
(访问web控制台http://10.96.72.64:8081/nexus/ 默认登录账号admin/admin123)
4、配置maven使用本地nexus仓库
sam@linux64:~/maven/apache-maven/conf> pwd
/home/sam/maven/apache-maven/conf
sam@linux64:~/maven/apache-maven/conf> vi settings.xml
添加如下部分
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://10.96.72.64:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
4.1、通过nexus web控制台部署构件
sam@linux64:~/maven/apache-maven/conf> vi settings.xml
添加如下部分
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
修改需要部署的构件maven项目的POM文件
sam@linux64:~/maven/proj/hello-world> ll
total 8
-rw-r--r-- 1 sam users 442 Jan 22 13:41 pom.xml
drwxr-xr-x 3 sam users 4096 Jan 22 13:42 src
sam@linux64:~/maven/proj/hello-world> ll src/main/java/com/juvenxu/mvnbook/helloworld/HelloWorld.java
-rw-r--r-- 1 sam users 219 Jan 22 13:43 src/main/java/com/juvenxu/mvnbook/helloworld/HelloWorld.java
sam@linux64:~/maven/proj/hello-world> vi pom.xml
添加如下部分
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://10.96.72.64:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://10.96.72.64:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
(将hello-world构件部署到本地nexus仓库)
sam@linux64:~/maven/proj/hello-world> mvn clean deploy
4.3、依赖本地nexus构件
环境说明
---------------------------
sam@linux64:~> cat /etc/issue
Welcome to SUSE Linux Enterprise Server 11 (x86_64) - Kernel \r (\l).
sam@linux64:~> uname -a
Linux linux64 2.6.27.19-5-default #1 SMP 2009-02-28 04:40:21 +0100 x86_64 x86_64 x86_64 GNU/Linux
Maven 3.0.4
http://www.fayea.com/apache-mirror/maven/maven-3/3.0.4/binaries/apache-maven-3.0.4-bin.tar.gz
Nexus 2.3.0
http://www.sonatype.org/downloads/nexus-2.3.0-04-bundle.tar.gz
安装步骤
---------------------------
1、下载解压apache-maven-3.0.4、建立软连接
sam@linux64:~/maven> pwd
/home/sam/maven
sam@linux64:~/maven> ll
total 33184
lrwxrwxrwx 1 sam users 18 Jan 22 11:09 apache-maven -> apache-maven-3.0.4
drwxr-xr-x 6 sam users 4096 Jan 22 11:09 apache-maven-3.0.4
2、配置环境 & 下载maven必要的插件
echo 'export M2_HOME=/home/sam/maven/apache-maven' >> ~/.bashrc
echo 'export PATH=$PATH:$M2_HOME/bin' >> ~/.bashrc
sam@linux64:~/maven> pwd
/home/sam/maven
sam@linux64:~/maven> vi apache-maven/conf/settings.xml
( add line <localRepository>/home/sam/maven/repo</localRepository> )
sam@linux64:~/maven> mvn help:system
sam@linux64:~/maven> ll repo/
total 40
drwxr-xr-x 3 sam users 4096 Jan 22 12:14 classworlds
drwxr-xr-x 3 sam users 4096 Jan 22 12:15 com
drwxr-xr-x 3 sam users 4096 Jan 22 12:14 commons-cli
drwxr-xr-x 3 sam users 4096 Jan 22 12:15 commons-lang
drwxr-xr-x 3 sam users 4096 Jan 22 12:15 jdom
drwxr-xr-x 3 sam users 4096 Jan 22 12:14 jtidy
drwxr-xr-x 3 sam users 4096 Jan 22 12:14 junit
drwxr-xr-x 4 sam users 4096 Jan 22 12:13 org
drwxr-xr-x 4 sam users 4096 Jan 22 12:14 plexus
drwxr-xr-x 3 sam users 4096 Jan 22 12:15 xpp3
3、下载安装Nexus 2.3.0
sam@linux64:~/maven> pwd
/home/sam/maven
sam@linux64:~/maven> tar xzvf nexus-2.3.0-04-bundle.tar.gz
sam@linux64:~/maven> ln -s nexus-2.3.0-04 nexus
sam@linux64:~/maven> echo 'export NEXUS_HOME=/home/sam/maven/nexus' >> ~/.bashrc
sam@linux64:~/maven> echo 'export CLASSPATH=$CLASSPATH:$NEXUS_HOME/lib' >> ~/.bashrc
sam@linux64:~/maven/nexus/bin> pwd
/home/sam/maven/nexus/bin
sam@linux64:~/maven/nexus/bin> ./nexus start
Starting Nexus OSS...
Started Nexus OSS.
(访问web控制台http://10.96.72.64:8081/nexus/ 默认登录账号admin/admin123)
4、配置maven使用本地nexus仓库
sam@linux64:~/maven/apache-maven/conf> pwd
/home/sam/maven/apache-maven/conf
sam@linux64:~/maven/apache-maven/conf> vi settings.xml
添加如下部分
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://10.96.72.64:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
4.1、通过nexus web控制台部署构件
sam@linux64:~/maven/apache-maven/conf> vi settings.xml
添加如下部分
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
修改需要部署的构件maven项目的POM文件
sam@linux64:~/maven/proj/hello-world> ll
total 8
-rw-r--r-- 1 sam users 442 Jan 22 13:41 pom.xml
drwxr-xr-x 3 sam users 4096 Jan 22 13:42 src
sam@linux64:~/maven/proj/hello-world> ll src/main/java/com/juvenxu/mvnbook/helloworld/HelloWorld.java
-rw-r--r-- 1 sam users 219 Jan 22 13:43 src/main/java/com/juvenxu/mvnbook/helloworld/HelloWorld.java
sam@linux64:~/maven/proj/hello-world> vi pom.xml
添加如下部分
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://10.96.72.64:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://10.96.72.64:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
(将hello-world构件部署到本地nexus仓库)
sam@linux64:~/maven/proj/hello-world> mvn clean deploy
部署成功后,可以通过web管理台查看
4.3、依赖本地nexus构件