Nexus私服搭建簡易步驟:
1、先到oracle下載最新JDK這裏下載最新jdk1.8
https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html
然後上傳到服務器解壓至/usr/java
修改
vi /etc/profile
加入
export JAVA_HOME=/usr/java/default
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/lib:$JAVA_HOME/bin:$PATH:$HOME/bin:$PATH
export JAVA_TOOLS=$JAVA_HOME/lib/tools.jar
修改軟連接:
ln -s /usr/java/jdk1.8.0_181 /usr/java/lastest
source /etc/profile
如果lastest已存在,先刪除,因爲事先jdk安裝時,JAVA_HOME存放的就是軟鏈接地址方便更換
2、下載neuxs3.X版本。到 /data/nexus 解壓
進入目錄
cd /data/nexus/nexus-3.13.0-01/bin
啓動
./nexus run &
如果要修改端口可到
vi /data/nexus/sonatype-work/nexus3/etc/nexus.properties
內修改
application-port
啓動後通過鏈接訪問 http://ip:9901 admin/dbjr66
若有設置防火牆,需前往修改防火牆配置並重啓防火牆
centos7.3關閉防火牆
關閉firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
firewall-cmd --state #查看默認防火牆狀態(關閉後顯示notrunning,開啓後顯示running)
[root@xiniu ~]# systemctl stop firewalld.service
[root@xiniu ~]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@xiniu ~]# firewall-cmd --state
not running
3、設置開機自啓動
進入到/etc/init.d目錄下,新建一個nexus腳本
cd /etc/init.d
vi nexus
#!/bin/bash
#chkconfig:2345 20 90
#description:nexus
#processname:nexus
export JAVA_HOME=/usr/java/default
case $1 in
start) su root /data/nexus/nexus-3.13.0-01/bin/nexus start;;
stop) su root /data/nexus/nexus-3.13.0-01/bin/nexus stop;;
status) su root /data/nexus/nexus-3.13.0-01/bin/nexus status;;
restart) su root /data/nexus/nexus-3.13.0-01/bin/nexus restart;;
dump ) su root /data/nexus/nexus-3.13.0-01/bin/nexus dump ;;
console ) su root /data/nexus/nexus-3.13.0-01/bin/nexus console ;;
*) echo "require console | start | stop | restart | status | dump " ;;
esac
給腳本添加執行權限 chmod +x nexus
添加系統服務
#chkconfig --add nexus
#chkconfig --levels 345 nexus on
查看開機自啓的服務中是否已經有我們的nexus
# chkconfig --list nexus
4、下載maven壓縮包,複製maven/conf 下的setting.xml文件到C:\Users\Administrator\.m2下,並修改。
在<settings>內加入本地倉庫地址
<!-- 配置本地倉庫地址 -->
<localRepository>C:\Users\Administrator\.m2\repository</localRepository>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>dbjr66</password>
</server>
</servers>
<mirrors>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>repo1 maven</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
</mirrors>
編輯Eclipse內 Window -> Preferences->Maven->User Settings中settings.xml文件的地址,指向我們新複製的位置。
當前倉庫目錄如下
在maven項目中引入jar依賴查看效果
在pom中加入依賴
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.49</version>
</dependency>
再查看本地倉庫,已生成
5、配置Eclipse的Maven環境
添加正常maven啓動依賴
啓動maven 命令
mvn clean install
後查看nexus
我們的jar已經上傳成功。
第三方JAR上傳:
可通過nexus直接登錄用界面上傳,
注:要生成POM文件,拉取失敗時,需要把對應包內的 last...文件刪除再拉取
錯誤問題:
E:\workspace\webToMaven\src\dib\src\main\java\com\shove\util\StaticUtil.java:[1,0] 錯誤: 非法字符: \65279
解決方案:
- 找到對應的類
- 右鍵選擇 properties 將字符改爲 ISO-8859-1
- 把錯誤信息修改後,重新改爲 UTF-8