標籤:blog http os io 使用 java strong ar 檔案
安裝&配置Nexus
解壓後,應該獲得如下目錄結構:
- nexus-2.0.6是nexus服務主目錄
- sonatype-work是真正的倉庫,同時包含了nexus的配置,如定時任務、使用者配置等
nexus支援如下命令:
引用nexus { console | start | stop | restart | status | dump }
連接埠配置在nexus/conf/nexus.properties檔案中,檔案如下:
# Sonatype Nexus# ==============# This is the most basic configuration of Nexus.# Jetty sectionapplication-port=8081application-host=0.0.0.0nexus-webapp=${bundleBasedir}/nexusnexus-webapp-context-path=/nexus# Nexus sectionnexus-work=${bundleBasedir}/../sonatype-work/nexusruntime=${bundleBasedir}/nexus/WEB-INFpr.encryptor.publicKeyPath=/apr/public-key.txt
如果你需要修改nexus服務連接埠或IP,上面這段修改就是了。
啟動後,如下介面:
預設管理員帳號:
使用者名稱:admin
密碼:admin123
通常可以在maven工具裡找到的包,也可以在這裡找到:
定製任務
當然,為了讓你的nexus更加智能,需要做一些定時任務,譬如定期下載索引,加快本地mvn檢索速度。
以建立定期下載索引為例,在Administration選項中找到Scheduled Tasks,在視窗頁面點擊Add,進行配置:
除此之外,我還經常要添加一些額外的jar到nexus中,譬如我要追加BC的組件包到nexus中,供團隊其他開發成員使用。
找到View/Repositories,開啟Repositories視窗,選擇3rd party,進行如下配置:
之後,就可以在這裡找到該jar了:
私服配置
為了讓你的maven預設訪問你的私服,需要配置settings.xml:
<mirrors>...<mirror><id>nexus</id><mirrorOf>*</mirrorOf><name>Nexus Mirror</name><url>http://<Your Nexus IP>/nexus/content/groups/public</url></mirror>...</mirrors>...<profiles><profile><id>nexus</id><repositories><repository><id>nexus</id><name>local private nexus</name><url><Your Nexus IP>/nexus/content/groups/public</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></repository><repository><id>nexus</id><name>local private nexus</name><url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>nexus</id><name>local private nexus</name><url>http://<Your Nexus IP>/nexus/content/groups/public</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></pluginRepository><pluginRepository><id>nexus</id><name>local private nexus</name><url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository></pluginRepositories></profile></profiles>...<activeProfiles><activeProfile>nexus</activeProfile></activeProfiles>
將jar部署至Nexus
如果通過Eclipse Maven工具,或者直接操作Maven命令列,將jar部署至nexus:
pom.xml
<project> ... <distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://<Your Nexus IP>/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://<Your Nexus IP>/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement> ... </project>
settings.xml
<settings> ... <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> ... </settings>
最後,在項目目錄中執行mvn deploy
如果想要在發布jar的同時,把source一通發布,需要做這個配置:
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><executions><execution><goals><goal>jar</goal></goals></execution></executions></plugin>
Maven零散筆記——配置Nexus