线上服务器安装maven私服
时间: 2025-05-05 19:07:54 浏览: 15
### 线上服务器部署 Maven 私服教程
#### 1. 下载并安装 Nexus Repository Manager
Nexus 是一种常用的 Maven 私服解决方案,可以用于托管和分发项目的依赖项。首先需要从官方网站下载 Nexus 的二进制文件。
官方下载地址为 http://www.sonatype.org/nexus/go[^3]。选择适合目标操作系统的版本进行下载,并解压到指定目录下。
#### 2. 启动 Nexus 服务
进入解压后的 Nexus 安装目录下的 `bin` 文件夹,在 Linux 或 macOS 上运行以下命令启动服务:
```bash
./nexus start
```
对于 Windows 用户,则可以通过双击 `nexus.bat` 脚本来启动服务。默认情况下,Nexus 使用的是 8081 端口,因此可以通过浏览器访问 URL 地址来确认服务是否正常工作:
http://<server-ip>:8081/nexus/
初始管理员账户的用户名为 `admin`,密码可以在日志文件中找到,默认路径位于 `<install-dir>/sonatype-work/nexus3/admin.password` 中。
#### 3. 配置 Maven 设置文件
为了使本地开发环境能够连接到线上私服,需修改用户的全局或个人 `.m2/settings.xml` 文件。以下是典型的配置片段:
```xml
<servers>
<server>
<id>nexus-releases</id> <!-- 对应于pom.xml中的repository id -->
<username>your-username</username>
<password>your-password</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-mirror</id>
<name>Nexus Mirror of Central</name>
<url>http://<server-ip>:8081/repository/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://<server-ip>:8081/repository/maven-central/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central-plugins</id>
<url>http://<server-ip>:8081/repository/maven-plugin/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
```
上述设置定义了一个镜像仓库以及发布和快照存储库的位置[^1]。
#### 4. 将项目上传至私服
通过执行如下命令可将构建好的 JAR/WAR 文件推送到私服:
```bash
mvn clean deploy -DaltDeploymentRepository=nexus-releases::default::http://<server-ip>:8081/repository/releases/
```
此命令会依据 POM 文件中的坐标信息自动完成构件的上传过程[^2]。
#### 5. 远程 Tomcat 热部署 (可选)
如果希望进一步简化应用更新流程,还可以利用 Cargo 插件或其他方式实现远程 Tomcat 的热部署功能[^4]。
---
###
阅读全文
相关推荐
















