maven

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
  3.     <modelVersion>4.0.0</modelVersion> 
  4.     <!-- 定義當前Maven項目隸屬的實際項目爲域名的反向順序  --> 
  5.     <groupId>com.juvenxu.mvnbook</groupId> 
  6.     <!-- 實際項目的名稱 --> 
  7.     <artifactId>hello-world</artifactId> 
  8.     <version>1.0-SNAPSHOT</version> 
  9.     <name>Maven Hello word Project</name> 
  10.  
  11.     <properties> 
  12.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
  13.     </properties> 
  14.  
  15.     <dependencies> 
  16.         <dependency> 
  17.             <groupId>junit</groupId> 
  18.             <artifactId>junit</artifactId> 
  19.             <version>4.7</version> 
  20.             <scope>test</scope> 
  21.         </dependency> 
  22.  
  23.         <dependency> 
  24.             <groupId>com.oracle.qudong</groupId> 
  25.             <artifactId>jdbc-qudong</artifactId> 
  26.             <version>10</version> 
  27.         </dependency> 
  28.         <dependency> 
  29.             <groupId>com.juvenxu.mvnbook.account</groupId> 
  30.             <!-- 實際項目的名稱 --> 
  31.             <artifactId>account-email</artifactId> 
  32.             <version>1.0-SNAPSHOT</version> 
  33.         </dependency> 
  34.  
  35.     </dependencies> 
  36.  
  37.  <!--上傳快照-->
  38.     <distributionManagement> 
  39.         <repository> 
  40.             <id>releases</id> 
  41.             <name>Internal Releases</name> 
  42.             <url>http://localhost:8080/nexus-2.1.1/content/repositories/myHosted/</url> 
  43.         </repository> 
  44.         <snapshotRepository> 
  45.             <id>Snapshots</id> 
  46.             <name>Internal Snapshots</name> 
  47.             <url>http://localhost:8080/nexus-2.1.1/content/repositories/snapshots/</url> 
  48.         </snapshotRepository> 
  49.     </distributionManagement> 
  50.  
  51.  
  52. </project> 
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
  3.     <modelVersion>4.0.0</modelVersion> 
  4.     <!-- 定義當前Maven項目隸屬的實際項目爲域名的反向順序  --> 
  5.     <groupId>com.juvenxu.mvnbook.account</groupId> 
  6.     <!-- 實際項目的名稱 --> 
  7.     <artifactId>account-email</artifactId> 
  8.     <version>1.0-SNAPSHOT</version> 
  9.     <name>Maven Hello word Project</name> 
  10.      
  11.     <properties> 
  12.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
  13.         <springframework.version>2.5.6</springframework.version> 
  14.     </properties> 
  15.      
  16.         <dependencies> 
  17.             <dependency> 
  18.                 <groupId>org.springframework</groupId> 
  19.                 <artifactId>spring-core</artifactId> 
  20.                 <version>${springframework.version}</version> 
  21.             </dependency> 
  22.              
  23.             <dependency> 
  24.                 <groupId>org.springframework</groupId> 
  25.                 <artifactId>spring-beans</artifactId> 
  26.                 <version>${springframework.version}</version> 
  27.             </dependency> 
  28.              
  29.             <dependency> 
  30.                 <groupId>org.springframework</groupId> 
  31.                 <artifactId>spring-context</artifactId> 
  32.                 <version>${springframework.version}</version> 
  33.             </dependency> 
  34.              
  35.             <dependency> 
  36.                 <groupId>org.springframework</groupId> 
  37.                 <artifactId>spring-context-support</artifactId> 
  38.                 <version>${springframework.version}</version> 
  39.             </dependency> 
  40.              
  41.             <dependency> 
  42.                 <groupId>javax.mail</groupId> 
  43.                 <artifactId>mail</artifactId> 
  44.                 <version>1.4.1</version> 
  45.             </dependency> 
  46.              
  47.             <dependency> 
  48.                 <groupId>junit</groupId> 
  49.                 <artifactId>junit</artifactId> 
  50.                 <version>4.7</version> 
  51.                 <scope>test</scope> 
  52.             </dependency> 
  53.              
  54.             <dependency> 
  55.                 <groupId>com.icegreen</groupId> 
  56.                 <artifactId>greenmail</artifactId> 
  57.                 <version>1.3.1b</version> 
  58.                 <scope>test</scope> 
  59.             </dependency> 
  60.         </dependencies> 
  61.          
  62.         <!--build> 
  63.             <plugins> 
  64.                 <plugin> 
  65.                     <groupId>org.apache.maven.plugins</groupId> 
  66.                     <artifactId>maven-compiler-plugin</artifactId> 
  67.                     <configuration> 
  68.                         <source>1.5</source> 
  69.                         <target>1.5</target> 
  70.                     </configuration>     
  71.                 </plugin>    
  72.             </plugins> 
  73.         </build--> 
  74.  
  75.      
  76. </project> 

 

以上爲兩個pom實例

 

再看maven的配置文件

 

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2.  
  3. <!-- 
  4. Licensed to the Apache Software Foundation (ASF) under one 
  5. or more contributor license agreements.  See the NOTICE file 
  6. distributed with this work for additional information 
  7. regarding copyright ownership.  The ASF licenses this file 
  8. to you under the Apache License, Version 2.0 (the 
  9. "License"); you may not use this file except in compliance 
  10. with the License.  You may obtain a copy of the License at 
  11.  
  12.     http://www.apache.org/licenses/LICENSE-2.0 
  13.  
  14. Unless required by applicable law or agreed to in writing, 
  15. software distributed under the License is distributed on an 
  16. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
  17. KIND, either express or implied.  See the License for the 
  18. specific language governing permissions and limitations 
  19. under the License. 
  20. --> 
  21.  
  22. <!-- 
  23.  | This is the configuration file for Maven. It can be specified at two levels: 
  24.  | 
  25.  |  1. User Level. This settings.xml file provides configuration for a single user,  
  26.  |                 and is normally provided in ${user.home}/.m2/settings.xml. 
  27.  | 
  28.  |                 NOTE: This location can be overridden with the CLI option: 
  29.  | 
  30.  |                 -s /path/to/user/settings.xml 
  31.  | 
  32.  |  2. Global Level. This settings.xml file provides configuration for all Maven 
  33.  |                 users on a machine (assuming they're all using the same Maven 
  34.  |                 installation). It's normally provided in  
  35.  |                 ${maven.home}/conf/settings.xml. 
  36.  | 
  37.  |                 NOTE: This location can be overridden with the CLI option: 
  38.  | 
  39.  |                 -gs /path/to/global/settings.xml 
  40.  | 
  41.  | The sections in this sample file are intended to give you a running start at 
  42.  | getting the most out of your Maven installation. Where appropriate, the default 
  43.  | values (values used when the setting is not specified) are provided. 
  44.  | 
  45.  |--> 
  46. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  
  47.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  48.           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 
  49.   <!-- localRepository 
  50.    | The path to the local repository maven will use to store artifacts. 
  51.    | 
  52.    | Default: ~/.m2/repository 
  53.   <localRepository>/path/to/local/repo</localRepository> 
  54.   --> 
  55.  
  56.   <!-- interactiveMode 
  57.    | This will determine whether maven prompts you when it needs input. If set to false, 
  58.    | maven will use a sensible default value, perhaps based on some other setting, for 
  59.    | the parameter in question. 
  60.    | 
  61.    | Default: true 
  62.   <interactiveMode>true</interactiveMode> 
  63.   --> 
  64.  
  65.   <!-- offline 
  66.    | Determines whether maven should attempt to connect to the network when executing a build. 
  67.    | This will have an effect on artifact downloads, artifact deployment, and others. 
  68.    | 
  69.    | Default: false 
  70.   <offline>false</offline> 
  71.   --> 
  72.  
  73.   <!-- pluginGroups 
  74.    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e. 
  75.    | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers 
  76.    | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list. 
  77.    |--> 
  78.   <pluginGroups> 
  79.     <!-- pluginGroup 
  80.      | Specifies a further group identifier to use for plugin lookup. 
  81.     <pluginGroup>com.your.plugins</pluginGroup> 
  82.     --> 
  83.   </pluginGroups> 
  84.  
  85.   <!-- proxies 
  86.    | This is a list of proxies which can be used on this machine to connect to the network. 
  87.    | Unless otherwise specified (by system property or command-line switch), the first proxy 
  88.    | specification in this list marked as active will be used. 
  89.    |--> 
  90.   <proxies> 
  91.     <!-- proxy 
  92.      | Specification for one proxy, to be used in connecting to the network. 
  93.      | 
  94.     <proxy> 
  95.       <id>optional</id> 
  96.       <active>true</active> 
  97.       <protocol>http</protocol> 
  98.       <username>proxyuser</username> 
  99.       <password>proxypass</password> 
  100.       <host>proxy.host.net</host> 
  101.       <port>80</port> 
  102.       <nonProxyHosts>local.net|some.host.com</nonProxyHosts> 
  103.     </proxy> 
  104.     --> 
  105.   </proxies> 
  106.  
  107.   <!-- servers 
  108.    | This is a list of authentication profiles, keyed by the server-id used within the system. 
  109.    | Authentication profiles can be used whenever maven must make a connection to a remote server. 
  110.    |--> 
  111.   <servers> 
  112.     <server>  
  113.         <id>releases</id>  
  114.         <username>admin</username>  
  115.         <password>admin123</password>  
  116.         </server>  
  117.         <server>  
  118.         <id>Snapshots</id>  
  119.         <username>admin</username>  
  120.         <password>admin123</password>  
  121.         </server> 
  122.   </servers> 
  123.  
  124.   <!-- mirrors 
  125.    | This is a list of mirrors to be used in downloading artifacts from remote repositories. 
  126.    |  
  127.    | It works like this: a POM may declare a repository to use in resolving certain artifacts. 
  128.    | However, this repository may have problems with heavy traffic at times, so people have mirrored 
  129.    | it to several places. 
  130.    | 
  131.    | That repository definition will have a unique id, so we can create a mirror reference for that 
  132.    | repository, to be used as an alternate download site. The mirror site will be the preferred  
  133.    | server for that repository. 
  134.    |--> 
  135.   <mirrors> 
  136.     <!-- mirror 
  137.         配置鏡像讓MAVEN只使用私服 
  138.      | Specifies a repository mirror site to use instead of a given repository. The repository that 
  139.      | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used 
  140.      | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. 
  141.      | --> 
  142.     <mirror> 
  143.       <id>nexus</id> 
  144.       <mirrorOf>*</mirrorOf> 
  145.       <name>sifu</name> 
  146.       <url>http://localhost:8080/nexus-2.1.1/content/groups/myGroup/</url> 
  147.     </mirror> 
  148.      
  149.   </mirrors> 
  150.    
  151.   <!-- profiles 
  152.     配置私服 
  153.    | 
  154.    |--> 
  155.   <profiles> 
  156.   
  157.     <profile> 
  158.       <id>nexus</id> 
  159.  
  160.       <repositories> 
  161.         <repository> 
  162.           <id>nexus</id> 
  163.           <name>nexus</name> 
  164.           <url>http://localhost:8080/nexus-2.1.1/content/groups/myGroup/</url> 
  165.             <releases><enabled>true</enabled></releases> 
  166.             <snapshots><enabled>true</enabled></snapshots> 
  167.         </repository> 
  168.       </repositories> 
  169.       <pluginRepositories> 
  170.         <pluginRepository> 
  171.              <id>central</id> 
  172.            <name>central</name> 
  173.            <url>http://localhost:8080/nexus-2.1.1/content/groups/myGroup/</url> 
  174.              <releases><enabled>true</enabled></releases> 
  175.            <snapshots><enabled>true</enabled></snapshots> 
  176.         </pluginRepository> 
  177.       </pluginRepositories>  
  178.     </profile> 
  179.  
  180.   </profiles> 
  181.  
  182.    
  183.  
  184.   <activeProfiles> 
  185.     <activeProfile>nexus</activeProfile> 
  186.     
  187.   </activeProfiles> 
  188.   
  189. </settings> 

 

只作爲自己學習的筆記

maven 三個生命週期,獨立的。分別爲 clean default site;

 

常用依賴範圍:compile 編譯依賴

          test  測試 

 

私服: nexus-2.1.1

http://www.sonatype.org/nexus/go

  倉庫解釋:maven--直接訪問自定義的倉庫組

            倉庫組包含各種倉庫   包括 宿主倉庫及代理倉庫等。

            宿主倉庫 可以手動添加第三方構建

            代理倉庫 訪問遠程倉庫,下載構建 並緩存

            兩個倉庫 類型又可分爲Release和Snapshot

             Release  放發佈版本, Snapshot   放快照版本即 不穩定的版本

倉庫設計圖例:

 

      

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章