本地 maven settings.xml 配置
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.1.106:8082/nexus/content/groups/public/</url>
</mirror>
</mirrors>
复制代码
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
复制代码
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-release</id>
<name>Spring Maven Release Repository</name>
<url>http://repo.springsource.org/libs-release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!--激活id为nexus的profile-->
<activeProfiles>
 <activeProfile>nexus</activeProfile>
</activeProfiles>
复制代码
项目pom.xml文件配置
- xml 中添加如下配置:
<!--发布自己的项目到 私服-->
<distributionManagement>
<repository>
<id>releases</id> <!--这里的id与 maven config sttings.xml server 中配置的id要一致-->
<name>Nexus Release Repository</name>
<url>http://192.168.1.106:8082/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id><!--这里的id与 maven config sttings.xml server 中配置的id要一致-->
<name>Nexus Snapshot Repository</name>
<url>http://192.168.1.106:8082/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
复制代码
系统会根据你当前项目是 releases
版本还是 snapshots
上传到指定的私服位置,如: <version>1.0-SNAPSHOT</version>
即为 snapshots 版, <version>1.0</version>
为 发行版(releases)。
- 通过maven 命令发布到私服
mvn deploy
, 也可通过图像界面发布,根据自己的喜好。 1.eclipse 建立 maven deploy 选项(IDEA自带有):右击项目,依次执行:Run As --> Run Configurations ---> Maven Build --->New _Configuration(双击Maven Build可生成) --> Browse Workspace 选中项目,Goals输入 : deploy -e 后,点击 Run。
- 引用公司发布的项目可登录nexus 后复制引用
dependency
,如下图位置:
私服访问地址:http://192.168.1.106:8082/nexus/
点击右上角log in : username:admin password:admin123