maven添加远程仓库以及导出依赖的jar包以及常用操作收集

来源:互联网 发布:网络摄像机哪个好 编辑:程序博客网 时间:2024/06/06 01:32

http://dreamoftch.iteye.com/blog/1976794

Maven常见的问题集锦 

 

先说结果吧,要添加其它的远程仓库,需要在maven的conf目录下的setting.xml里面添加下面配置:

 

在   <profiles> 节点下添加(里面的url地址就是仓库的地址,根据自己的情况替换就好了):

 

 

Xml代码  收藏代码
  1. <profile>  
  2.       <id>dev</id>  
  3.       <repositories>    
  4.         <repository>    
  5.           <id>company</id>    
  6.           <name>company</name>    
  7.           <url>http://192.168.2.202:8081/nexus/content/repositories/releases/</url>    
  8.           <releases>    
  9.             <enabled>true</enabled>    
  10.           </releases>    
  11.           <snapshots>    
  12.             <enabled>false</enabled>    
  13.           </snapshots>    
  14.         </repository>    
  15.       </repositories>    
  16.       <pluginRepositories>    
  17.         <pluginRepository>    
  18.           <id>company</id>    
  19.           <name>company</name>    
  20.           <url>http://192.168.2.202:8081/nexus/content/repositories/releases/</url>    
  21.           <releases>    
  22.             <enabled>true</enabled>    
  23.           </releases>    
  24.           <snapshots>    
  25.             <enabled>false</enabled>    
  26.           </snapshots>        
  27.         </pluginRepository>    
  28.       </pluginRepositories>       
  29.     </profile>  

 

 

同时在setting.xml最后</settings>之前加上下面的(这里的dev就是上面repository的id):

 

 

Xml代码  收藏代码
  1. <activeProfiles>  
  2.     <activeProfile>dev</activeProfile>  
  3.   </activeProfiles>  

 

 

这样就可以从其它的仓库下载了

 

 

参考:

Maven最佳实践:Maven仓库

 

 

从Maven仓库中导出jar包:进入工程pom.xml 所在的目录下,输入:

 

Java代码  收藏代码
  1. mvn dependency:copy-dependencies  

 

会导出到targed/dependency 下面

 

可以在工程创建lib文件夹,输入以下命令:

 

Java代码  收藏代码
  1. mvn dependency:copy-dependencies -DoutputDirectory=lib    

 

这样jar包都会copy到工程目录下的lib里面

 

可以设置依赖级别,通常用编译需要的jar

 

Java代码  收藏代码
  1. mvn dependency:copy-dependencies -DoutputDirectory=lib   -DincludeScope=compile  

 

 

 

参考:

Maven导出工程依赖的jar包

 

 

查看一个插件的常用命令描述:

 

 

Java代码  收藏代码
  1. mvn help:describe -Dplugin=插件名字  

 

 

例如:

 

 

Java代码  收藏代码
  1. mvn help:describe -Dplugin=dependency  

 

 

 

可以查看dependency插件的常用命令。

 

查看一个插件的常用命令以及完整描述:

 

 

Java代码  收藏代码
  1. mvn help:describe -Dplugin=插件名字 -Dfull  

 

 

 例如:

 

Java代码  收藏代码
  1. mvn help:describe -Dplugin=dependency -Dfull  

 

查看dependency插件的完整命令描述

 

 

创建一个最简单的maven项目:

 
Java代码  收藏代码
  1. mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false  -DgroupId=com.tch.test -DartifactId=simpleMavenProject  
 
 

maven  web项目:

 

Java代码  收藏代码
  1. mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=com.mycompany.app -DartifactId=my-webapp  

 

 
maven下载依赖jar包的源码和javadoc:
Java代码  收藏代码
  1. mvn dependency:sources  
  2. mvn dependency:resolve -Dclassifier=javadoc  
 
 
maven多模块示例:
假设在名字为simple-parent的文件夹下面有一个pom.xml (也就是所谓的父模块pom.xml)、一个名字为 firstChild 的文件夹(里面是一个maven子模块)、一个名字为secondChild的文件夹(里面也是一个maven子模块)
 
其中父模块pom.xml 内容为:
注意:模块的加载顺序和该模块在父模块的pom.xml中配置的顺序有关,例如下面的firstChild就会先于secondChild模块
 
Xml代码  收藏代码
  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  
  3. http://maven.apache.org/maven-v4_0_0.xsd">  
  4.     <modelVersion>4.0.0</modelVersion>  
  5.     <groupId>com.tch</groupId>  
  6.     <artifactId>maven-parent</artifactId>  
  7.     <!-- 父模块的packaging要配置为pom,表明这是个单纯的pom文件 -->  
  8.     <packaging>pom</packaging>  
  9.     <version>1.0</version>  
  10.     <name>Chapter 6 Simple Parent Project</name>  
  11.     <modules>  
  12.         <!-- 这里配置子模块的artifactId列表 -->  
  13.         <module>firstChild</module>  
  14.         <module>secondChild</module>  
  15.     </modules>  
  16. </project>  
  
firstChild 的pom.xml :
Xml代码  收藏代码
  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.       
  5.     <!-- 这里配置父模块的坐标 -->  
  6.     <parent>  
  7.         <groupId>com.tch</groupId>  
  8.         <artifactId>maven-parent</artifactId>  
  9.         <version>1.0</version>  
  10.     </parent>  
  11.   
  12.     <!-- 这里可以省去groupId的配置,因为该配置与父模块的groupId一样,所以可省略 -->  
  13.     <artifactId>firstChild</artifactId>  
  14.     <version>1.0</version>  
  15.     <packaging>jar</packaging>  
  16.   
  17.     <properties>  
  18.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  19.     </properties>  
  20. </project>  
 
 
secondChild 模块的pom.xml : 
Xml代码  收藏代码
  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/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.   
  5.     <!-- 这里配置父模块的坐标 -->  
  6.     <parent>  
  7.         <groupId>com.tch</groupId>  
  8.         <artifactId>maven-parent</artifactId>  
  9.         <version>1.0</version>  
  10.     </parent>  
  11.   
  12.     <!-- 这里可以省去groupId的配置,因为该配置与父模块的groupId一样,所以可省略 -->  
  13.     <artifactId>secondChild</artifactId>  
  14.     <packaging>war</packaging>  
  15.     <version>1.0</version>  
  16.   
  17.     <properties>  
  18.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  19.     </properties>  
  20.     <build>  
  21.         <finalName>webmaven</finalName>  
  22.         <plugins>  
  23.             <!-- 配置jetty -->  
  24.             <plugin>  
  25.                 <groupId>org.mortbay.jetty</groupId>  
  26.                 <artifactId>maven-jetty-plugin</artifactId>  
  27.             </plugin>  
  28.         </plugins>  
  29.     </build>  
  30. </project>  
 
 
 在父pom.xml中配置 dependency 和 配置 dependencyManagement 的区别:
在父pom.xml中配置dependency的话,子模块就会继承该依赖,假如父pom.xml中配置了下面的依赖:
Xml代码  收藏代码
  1. <dependency>  
  2.     <groupId>junit</groupId>  
  3.     <artifactId>junit</artifactId>  
  4.     <version>3.8.1</version>  
  5.     <scope>test</scope>  
  6. </dependency>  
 
 
然后在子模块运行下面命令查看子模块的依赖:
Java代码  收藏代码
  1. mvn dependency:resolve  
 
 
 就会发现子模块的依赖包含了上面再父pom.xml中配置的依赖。类似于java里面继承的效果。
 
如果在父pom.xml中配置dependencyManagement的话,假如dependencyManagement里面配置了上面同样的依赖:
Xml代码  收藏代码
  1. <dependencyManagement>  
  2.         <dependencies>  
  3.             <dependency>  
  4.                 <groupId>junit</groupId>  
  5.                 <artifactId>junit</artifactId>  
  6.                 <version>3.8.1</version>  
  7.                 <scope>test</scope>  
  8.             </dependency>  
  9.         </dependencies>  
  10.     </dependencyManagement>  
 
 
 然后在子模块运行
Java代码  收藏代码
  1. mvn dependency:resolve  
 
 查看子模块的依赖的话,就会发现子模块并没有继承父模块dependencyManagement里面配置的依赖。
要想使用父模块dependencyManagement里面配置的依赖,需要在子模块配置(注意没有version):
Xml代码  收藏代码
  1. <dependency>  
  2.     <groupId>junit</groupId>  
  3.     <artifactId>junit</artifactId>  
  4. </dependency>  
 
 ,然后在子模块运行
Java代码  收藏代码
  1. mvn dependency:resolve  
 
 命令查看子模块的依赖,就会发现子模块的依赖包含了junit,并且版本号是父pom.xml里面配置的版本号。
 
所以,dependencyManagement 其实是为了统一管理版本号,把公用的依赖放到dependencyManagement里面管理,在需要引用该依赖的地方只需要groupId和artifactId即可引用该依赖。避免了版本号不同引发的问题
 
 使用jetty插件运行web项目:
在pom.xml 的build 中添加jetty插件:(版本号自定)
Xml代码  收藏代码
  1. <plugin>  
  2.     <groupId>org.mortbay.jetty</groupId>  
  3.     <artifactId>maven-jetty-plugin</artifactId>  
  4.     <version>${jetty-version}</version>  
  5. </plugin>  
 
 然后运行命令:mvn jetty:run 即可
貌似如果运行tomcat插件的话,我这里直接运行  mvn tomcat:run  就可以了,没有配置tomcat插件。。。
 
 
使用Maven CXF插件根据WSDL生成java类:
Java代码  收藏代码
  1. <build>  
  2.     <plugins>  
  3.         <plugin>  
  4.             <groupId>org.apache.cxf</groupId>  
  5.             <artifactId>cxf-codegen-plugin</artifactId>  
  6.             <version>2.7.8</version>  
  7.             <executions>  
  8.                 <execution>  
  9.                     <id>generate-sources</id>  
  10.                     <phase>generate-sources</phase>  
  11.                     <configuration>  
  12.                         <sourceRoot>src/cxf</sourceRoot>  
  13.                         <wsdlOptions>  
  14.                             <wsdlOption>  
  15.                                 <wsdl>http://xxx?wsdl</wsdl>  
  16.                                 <frontEnd>jaxws21</frontEnd>  
  17.                                 <faultSerialVersionUID>1</faultSerialVersionUID>  
  18.                             </wsdlOption>  
  19.                         </wsdlOptions>  
  20.                     </configuration>  
  21.                     <goals>  
  22.                         <goal>wsdl2java</goal>  
  23.                     </goals>  
  24.                 </execution>  
  25.             </executions>  
  26.         </plugin>  
  27.     </plugins>  
  28. </build>  
 
然后执行 mvn generate-sources 即可在src/cxf目录下生成java类
 
将项目依赖的jar包的源码下载到目录dependency_src目录,但不解压(以jar格式):
Java代码  收藏代码
  1. mvn dependency:copy-dependencies -DoutputDirectory=dependency_src   -DincludeScope=compile -Dclassifier=sources  
 
 
将项目依赖的jar包的源码下载到目录dependency_src目录并解压:
Maven代码  收藏代码
  1. mvn dependency:unpack-dependencies -Dclassifier=sources -DfailOnMissingClassifierArtifact=false -DoutputDirectory=dependency_src -DincludeScope=compile  
 
 使用jacoco生成测试覆盖率report :
参考:http://www.eclemma.org/jacoco/trunk/doc/index.html  
  • Maven Usage Example - Offline Example
 
maven tomcat plugin : 在pom.xml中添加Plugin:然后运行:mvn tomcat7:run即可
Xml代码  收藏代码
  1. <build>  
  2.   <finalName>ssh</finalName>  
  3.   <plugins>  
  4.     <plugin>  
  5.       <groupId>org.apache.tomcat.maven</groupId>  
  6.       <artifactId>tomcat7-maven-plugin</artifactId>  
  7.       <version>2.2</version>  
  8.       <configuration>  
  9.         <!-- http port -->  
  10.         <port>9090</port>  
  11.         <!-- application path always starts with / -->  
  12.         <path>/</path>  
  13.       </configuration>  
  14.     </plugin>  
  15.   </plugins>  
  16. </build>  
 
maven jetty plugin:在pom.xml中添加plugin,然后运行: mvn jetty:run 即可
Xml代码  收藏代码
  1. <plugin>  
  2.                 <groupId>org.mortbay.jetty</groupId>  
  3.                 <artifactId>maven-jetty-plugin</artifactId>  
  4.                 <version>6.1.10</version>  
  5.                 <configuration>  
  6.                     <scanIntervalSeconds>5</scanIntervalSeconds>  
  7.                     <webAppConfig>  
  8.                         <contextPath>/</contextPath>  
  9.                     </webAppConfig>  
  10.                     <connectors>    
  11.                         <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">    
  12.                             <!-- jetty port -->  
  13.                             <port>18080</port>    
  14.                         </connector>    
  15.                     </connectors>   
  16.                 </configuration>  
  17.             </plugin>  
 
 
 多个module的时候,我们修改了某个module,然后只需要从该module开始build即可,这样就不必要build这个module之前的那些module了:(详细参考)
Xml代码  收藏代码
  1. mvn clean install -rf  module-name  
 
parent pom.xml和child pom.xml:
parent pom.xml:
Xml代码  收藏代码
  1. <modules>  
  2.   <module>my-modules/my-module-1</module>  
  3. </modules>  
 
The value of <module> is the relative path from the com.mycompany.app:my-app:1 to com.mycompany.app:my-module:1's POM(可以在链接中搜索这句话)
module的值,是从parent的pom.xml到该module的pom.xml的相对路径
child pom.xml:
Xml代码  收藏代码
  1. <parent>  
  2.   <groupId>parent-groupId</groupId>  
  3.   <artifactId>parent-artifactId</artifactId>  
  4.   <version>parent-version</version>  
  5.   <relativePath>../../pom.xml</relativePath>  
  6. </parent>  
 
relativePath的值,是从该module的pom.xml到parent的pom.xml的相对路径
 
国内maven 仓库地址:
Xml代码  收藏代码
  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: ${user.home}/.m2/repository  
  53.   <localRepository>/path/to/local/repo</localRepository>  
  54.   -->  
  55.   <localRepository>D:/Program Files/apache-maven-3.3.1/repository</localRepository>  
  56.   
  57.   <!-- interactiveMode  
  58.    | This will determine whether maven prompts you when it needs input. If set to false,  
  59.    | maven will use a sensible default value, perhaps based on some other setting, for  
  60.    | the parameter in question.  
  61.    |  
  62.    | Default: true  
  63.   <interactiveMode>true</interactiveMode>  
  64.   -->  
  65.   
  66.   <!-- offline  
  67.    | Determines whether maven should attempt to connect to the network when executing a build.  
  68.    | This will have an effect on artifact downloads, artifact deployment, and others.  
  69.    |  
  70.    | Default: false  
  71.   <offline>false</offline>  
  72.   -->  
  73.   
  74.   <!-- pluginGroups  
  75.    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.  
  76.    | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers  
  77.    | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.  
  78.    |-->  
  79.   <pluginGroups>  
  80.     <!-- pluginGroup  
  81.      | Specifies a further group identifier to use for plugin lookup.  
  82.     <pluginGroup>com.your.plugins</pluginGroup>  
  83.     -->  
  84.   </pluginGroups>  
  85.   
  86.   <!-- proxies  
  87.    | This is a list of proxies which can be used on this machine to connect to the network.  
  88.    | Unless otherwise specified (by system property or command-line switch), the first proxy  
  89.    | specification in this list marked as active will be used.  
  90.    |-->  
  91.   <proxies>  
  92.     <!-- proxy  
  93.      | Specification for one proxy, to be used in connecting to the network.  
  94.      |  
  95.     <proxy>  
  96.       <id>optional</id>  
  97.       <active>true</active>  
  98.       <protocol>http</protocol>  
  99.       <username>proxyuser</username>  
  100.       <password>proxypass</password>  
  101.       <host>proxy.host.net</host>  
  102.       <port>80</port>  
  103.       <nonProxyHosts>local.net|some.host.com</nonProxyHosts>  
  104.     </proxy>  
  105.     -->  
  106.   </proxies>  
  107.   
  108.   <!-- servers  
  109.    | This is a list of authentication profiles, keyed by the server-id used within the system.  
  110.    | Authentication profiles can be used whenever maven must make a connection to a remote server.  
  111.    |-->  
  112.   <servers>  
  113.     <!-- server  
  114.      | Specifies the authentication information to use when connecting to a particular server, identified by  
  115.      | a unique name within the system (referred to by the 'id' attribute below).  
  116.      |  
  117.      | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are  
  118.      |       used together.  
  119.      |  
  120.     <server>  
  121.       <id>deploymentRepo</id>  
  122.       <username>repouser</username>  
  123.       <password>repopwd</password>  
  124.     </server>  
  125.     -->  
  126.   
  127.     <!-- Another sample, using keys to authenticate.  
  128.     <server>  
  129.       <id>siteServer</id>  
  130.       <privateKey>/path/to/private/key</privateKey>  
  131.       <passphrase>optional; leave empty if not used.</passphrase>  
  132.     </server>  
  133.     -->  
  134.   </servers>  
  135.   
  136.   <!-- mirrors  
  137.    | This is a list of mirrors to be used in downloading artifacts from remote repositories.  
  138.    |  
  139.    | It works like this: a POM may declare a repository to use in resolving certain artifacts.  
  140.    | However, this repository may have problems with heavy traffic at times, so people have mirrored  
  141.    | it to several places.  
  142.    |  
  143.    | That repository definition will have a unique id, so we can create a mirror reference for that  
  144.    | repository, to be used as an alternate download site. The mirror site will be the preferred  
  145.    | server for that repository.  
  146.    |-->  
  147.     <mirrors>  
  148.         <!-- mirror | Specifies a repository mirror site to use instead of a given   
  149.             repository. The repository that | this mirror serves has an ID that matches   
  150.             the mirrorOf element of this mirror. IDs are used | for inheritance and direct   
  151.             lookup purposes, and must be unique across the set of mirrors. | <mirror>   
  152.             <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable   
  153.             Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url>   
  154.             </mirror> -->  
  155.         <mirror>  
  156.             <id>CN</id>  
  157.             <name>OSChina Central</name>  
  158.             <url>http://maven.oschina.net/content/groups/public/</url>  
  159.             <mirrorOf>central</mirrorOf>  
  160.         </mirror>  
  161.         <mirror>  
  162.             <id>ibiblio</id>  
  163.             <name>ibiblio</name>  
  164.             <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>  
  165.             <mirrorOf>central</mirrorOf>  
  166.         </mirror>  
  167.         <mirror>  
  168.             <id>jboss-public-repository-group</id>  
  169.             <name>JBoss Public Repository Group</name>  
  170.             <url>http://repository.jboss.org/nexus/content/groups/public</url>  
  171.             <mirrorOf>central</mirrorOf>  
  172.         </mirror>  
  173.     </mirrors>  
  174.   
  175.   <!-- profiles  
  176.    | This is a list of profiles which can be activated in a variety of ways, and which can modify  
  177.    | the build process. Profiles provided in the settings.xml are intended to provide local machine-  
  178.    | specific paths and repository locations which allow the build to work in the local environment.  
  179.    |  
  180.    | For example, if you have an integration testing plugin - like cactus - that needs to know where  
  181.    | your Tomcat instance is installed, you can provide a variable here such that the variable is  
  182.    | dereferenced during the build process to configure the cactus plugin.  
  183.    |  
  184.    | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles  
  185.    | section of this document (settings.xml) - will be discussed later. Another way essentially  
  186.    | relies on the detection of a system property, either matching a particular value for the property,  
  187.    | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a  
  188.    | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.  
  189.    | Finally, the list of active profiles can be specified directly from the command line.  
  190.    |  
  191.    | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact  
  192.    |       repositories, plugin repositories, and free-form properties to be used as configuration  
  193.    |       variables for plugins in the POM.  
  194.    |  
  195.    |-->  
  196.   <profiles>  
  197.     <!-- profile  
  198.      | Specifies a set of introductions to the build process, to be activated using one or more of the  
  199.      | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>  
  200.      | or the command line, profiles have to have an ID that is unique.  
  201.      |  
  202.      | An encouraged best practice for profile identification is to use a consistent naming convention  
  203.      | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.  
  204.      | This will make it more intuitive to understand what the set of introduced profiles is attempting  
  205.      | to accomplish, particularly when you only have a list of profile id's for debug.  
  206.      |  
  207.      | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.  
  208.     <profile>  
  209.       <id>jdk-1.4</id>  
  210.   
  211.       <activation>  
  212.         <jdk>1.4</jdk>  
  213.       </activation>  
  214.   
  215.       <repositories>  
  216.         <repository>  
  217.           <id>jdk14</id>  
  218.           <name>Repository for JDK 1.4 builds</name>  
  219.           <url>http://www.myhost.com/maven/jdk14</url>  
  220.           <layout>default</layout>  
  221.           <snapshotPolicy>always</snapshotPolicy>  
  222.         </repository>  
  223.       </repositories>  
  224.     </profile>  
  225.     -->  
  226.   
  227.     <!--  
  228.      | Here is another profile, activated by the system property 'target-env' with a value of 'dev',  
  229.      | which provides a specific path to the Tomcat instance. To use this, your plugin configuration  
  230.      | might hypothetically look like:  
  231.      |  
  232.      | ...  
  233.      | <plugin>  
  234.      |   <groupId>org.myco.myplugins</groupId>  
  235.      |   <artifactId>myplugin</artifactId>  
  236.      |  
  237.      |   <configuration>  
  238.      |     <tomcatLocation>${tomcatPath}</tomcatLocation>  
  239.      |   </configuration>  
  240.      | </plugin>  
  241.      | ...  
  242.      |  
  243.      | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to  
  244.      |       anything, you could just leave off the <value/> inside the activation-property.  
  245.      |  
  246.     <profile>  
  247.       <id>env-dev</id>  
  248.   
  249.       <activation>  
  250.         <property>  
  251.           <name>target-env</name>  
  252.           <value>dev</value>  
  253.         </property>  
  254.       </activation>  
  255.   
  256.       <properties>  
  257.         <tomcatPath>/path/to/tomcat/instance</tomcatPath>  
  258.       </properties>  
  259.     </profile>  
  260.     -->  
  261.   </profiles>  
  262.   
  263.   <!-- activeProfiles  
  264.    | List of profiles that are active for all builds.  
  265.    |  
  266.   <activeProfiles>  
  267.     <activeProfile>alwaysActiveProfile</activeProfile>  
  268.     <activeProfile>anotherAlwaysActiveProfile</activeProfile>  
  269.   </activeProfiles>  
  270.   -->  
  271. </settings>  
 
添加log4j  slf4j依赖:
Xml代码  收藏代码
  1. <dependency>  
  2.   <groupId>org.slf4j</groupId>  
  3.   <artifactId>slf4j-log4j12</artifactId>  
  4.   <version>1.7.2</version>  
  5. </dependency>