開源中國 Maven 庫使用協助

來源:互聯網
上載者:User

標籤:blog   http   使用   os   strong   檔案   io   for   

使用

   

接下來將簡單介紹如何在您的項目中使用 Maven,以及使用 OSChina 提供的 Maven 服務。

   

1.安裝 Maven 

   

如果需要使用到 Maven ,必須首先安裝 Maven , Maven 的在 Apache Maven 中有,您也可以點擊這裡下載 zip ,tar.gz。

   

下載好 Maven 後,需要簡單安裝下。將下載的  zip  或者  tar.gz  包解壓到需要安裝到的目錄。     接下簡單配置下環境變數:

1、建立環境變數  M2_HOME  ,輸入值為 Maven 的安裝目錄。

2、建立環境變數  M2  ,輸入值為:  %M2_HOME%\bin  。

3、將 M2 環境變數加入  Path  的最後,如:  ;%M2%  ;。

環境變數就這麼簡單配置下就可以了。開啟命令列視窗輸入  mvn -version  。可以看到如下輸出:


                             
           

看到以上輸出,您的 Maven 環境就已經搭建好了。

   

2.修改 settings.xml

   

    在 Maven 中使用 OSChina 的 Maven 服務還需要簡單配置一下 Maven,在 Maven 的安裝目錄下的 conf 檔案下有個  settings.xml  檔案,接下來我們需要對這個檔案做簡單的修改,修改前您可以簡單備份下該檔案。     開啟  settings.xml  檔案,按下面內容修改。或者點擊 settings.xml 下載

   
       

01 <mirrors>
02     <!-- mirror | Specifies a repository mirror site to use instead of a given
03         repository. The repository that | this mirror serves has an ID that matches
04         the mirrorOf element of this mirror. IDs are used | for inheritance and direct
05         lookup purposes, and must be unique across the set of mirrors. | -->
06     <mirror>
07         <id>nexus-osc</id>
08         <mirrorOf>*</mirrorOf>
09         <name>Nexus osc</name>
10         <url>http://maven.oschina.net/content/groups/public/</url>
11     </mirror>
12 </mirrors>

   
補充: 如果還需要osc的thirdparty倉庫或多個倉庫,需要如下修改:詳情

01 <mirrors>
02     <!-- mirror | Specifies a repository mirror site to use instead of a given
03         repository. The repository that | this mirror serves has an ID that matches
04         the mirrorOf element of this mirror. IDs are used | for inheritance and direct
05         lookup purposes, and must be unique across the set of mirrors. | -->
06     <mirror>
07         <id>nexus-osc</id>
08         <mirrorOf>central</mirrorOf>
09         <name>Nexus osc</name>
10         <url>http://maven.oschina.net/content/groups/public/</url>
11     </mirror>
12     <mirror>
13         <id>nexus-osc-thirdparty</id>
14         <mirrorOf>thirdparty</mirrorOf>
15         <name>Nexus osc thirdparty</name>
16         <url>http://maven.oschina.net/content/repositories/thirdparty/</url>
17     </mirror>
18 </mirrors>

   

    這裡是配置 Maven 的 mirror 地址指向OSChina 的 Maven 鏡像地址。     在執行 Maven 命令的時候, Maven 還需要安裝一些外掛程式包,這些外掛程式包的也讓其指向 OSChina 的 Maven 地址。修改如下內容。

   
       

01 <profile>
02     <id>jdk-1.4</id>
03
04     <activation>
05         <jdk>1.4</jdk>
06     </activation>
07
08     <repositories>
09         <repository>
10             <id>nexus</id>
11             <name>local private nexus</name>
12             <url>http://maven.oschina.net/content/groups/public/</url>
13             <releases>
14                 <enabled>true</enabled>
15             </releases>
16             <snapshots>
17                 <enabled>false</enabled>
18             </snapshots>
19         </repository>
20     </repositories>
21     <pluginRepositories>
22         <pluginRepository>
23             <id>nexus</id>
24             <name>local private nexus</name>
25             <url>http://maven.oschina.net/content/groups/public/</url>
26             <releases>
27                 <enabled>true</enabled>
28             </releases>
29             <snapshots>
30                 <enabled>false</enabled>
31             </snapshots>
32         </pluginRepository>
33     </pluginRepositories>
34 </profile>

   
   

如果您需要修改 Maven 的預設檔案儲存路徑,需要在 settings.xml 檔案中修改如下地方。

   
       

1 <localRepository>F:/Maven/repo/m2/</localRepository>

   
   

按照如上修改  settings.xml  之後,您就可以在自己的 Maven 中使用 OSChina 為您提供的 Maven 服務了。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.