搭建maven+nexus环境

本文详细介绍如何在SUSE Linux Enterprise Server 11上搭建Maven环境并配置Nexus作为私有仓库,包括Maven与Nexus的安装、配置及通过Maven部署构件到Nexus仓库的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[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控制台部署构件



4.2、通过maven部署构件

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构件


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值