远程仓库更新命令如下:
clean package deploy
1、配置账号密码,如下:
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> ... <servers> <!-- server | Specifies the authentication information to use when connecting to a particular server, identified by | a unique name within the system (referred to by the 'id' attribute below). | | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are | used together. | <server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server> --> <!-- Another sample, using keys to authenticate. <server> <id>siteServer</id> <privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave empty if not used.</passphrase> </server> --> <server> <id>releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> ... </settings>
2、配置pom.xml文件
注意这里的id要和pom.xml里远程deploy的地址对应一致,pom.xml配置,如下:
<!-- 配置远程发布到私服,clean package deploy -->
<distributionManagement> <repository> <id>releases</id> <name>Nexus Release Repository</name> <url>http://192.168.20.229:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://192.168.20.229:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
如果上述第2步操作,会报如下错误:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project Test: Failed to deploy artifacts: Could not transfer artifact com.test:Test:jar:0.0.1 from/to releases (http://192.168.20.229:8081/nexus/content/repositories/releases/): Access denied to http://192.168.20.229:8081/nexus/content/repositories/releases/com/test/Test/0.0.1/Test-0.0.1.jar. Error code 401, Unauthorized -> [Help 1]