能看懂英文当然更好,地址:配置文件官方说明https://maven.apache.org/settings.html
Maven项目的setting.xml文件,主要分为两个:
用户的安装: ${user.home}/.m2/settings.xml 当前用户范围的配置文件;
Maven安装:
maven.conf/settings.xml全局范围配置文件,修改后将影响本机所有的用户配置。说明:如果两个文件都存在,则它们的内容将被合并,特定于用户的settings.xml占主导地位。提示:如果是从头开始创建用户特定的设置,将全局设置从Maven安装复制到
{user.home} /.m2目录是最简单的方法。Maven的默认settings.xml是一个包含注释和示例的模板,可以快速调整它以符合需求。
注:当然意思不是说只能有两个,只是配置范围分为两个,但是可以复制很多份,相对应到eclipse或者idea中的workspace可以指向不同的配置文件,配置不同的仓库或者用户,可以根据实际使用需要区分开来。
setting.xml文件参数含义:
localRepository:自定义本地库路径,默认在 ${user.home}/.m2中;
interactiveMode: 交互模式,Maven是否应该尝试与用户输入交互,默认是true,如果不是false。
offline:是否每次编译都去查找远程中心库, 如果此构建系统应以离线模式运行,则为true,默认为false。由于网络设置或安全原因,此元素对于构建无法连接到远程存储库的服务器非常有用。
pluginGroups:插件组,例如org.mortbay.jetty;
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
...
</settings>
例如,给定上述设置Maven命令可以执行:
mvn jetty:run
- servers:服务器;
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>${user.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
...
</settings>
id:与Maven试图连接的资源库/镜像的id元素相匹配的服务器的标识(不是用户登录的标识)。
username, password:表示向该服务器进行身份验证所需的登录名和密码。
privateKey,passphrase:和前面的两个元素一样,如果需要的话,这一对指定一个私钥的路径(默认是${user.home}/.ssh/id_dsa)和密码。该密码和密码的元素可能在将来被外部化,但现在他们必须设置在纯文本的settings.xml文件。
filePermissions,directoryPermissions:在部署中创建存储库文件或目录时,这些是要使用的权限。每个的合法值是一个三位数的数字,相当于* nix文件的权限,如:664或775。
注意:如果使用私钥登录到服务器,请确保省略元素。否则,该键将被忽略。
Maven 2.1.0以上版本支持服务器密码加密
有这方面的兴趣或需求可以参考https://maven.apache.org/guides/mini/guide-encryption.html
- mirrors:镜像库,可以指定内部中心库;
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<mirrors>
<mirror>
<id>planetmirror.com</id>
<name>PlanetMirror Australia</name>
<url>http://downloads.planetmirror.com/pub/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
...
</settings>
id,name:镜像的唯一标识符和用户的名字。该id用于区分镜像元素,并在连接镜像时从部分选择相应的凭据。
url:镜像的基本URL。构建系统将使用此URL来连接到存储库,而不是原始存储库URL。
mirrorOf:这是一个镜像的存储库的ID。
例如,要指向Maven 中央存储库(https://repo.maven.apache.org/maven2/)的镜像,设置为central。也可以设置为repo1,repo2或*,!inhouse。
- proxies:个性配置,需要在中激活;
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<proxies>
<proxy>
<id>myproxy</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.somewhere.com</host>
<port>8080</port>
<username>proxyuser</username>
<password>somepassword</password>
<nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
</proxy>
</proxies>
...
</settings>
id:此代理的唯一标识符,用于区分代理元素。
active:如果此代理处于活动状态,则为true。对于声明一组代理是必需的,但是一次只能激活一个代理。
protocol, host, port: :protocol://host:port。
username, password:表示对此代理服务器进行身份验证所需的登录名和密码。
nonProxyHosts:这是不应代理的主机列表。
- activeProfiles:表示激活的profile,加载所需的环境设置。
<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
https://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.5</jdk>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>mavenVersion</name>
<value>2.0.3</value>
</property>
<file>
<exists>${basedir}/file2.properties</exists>
<missing>${basedir}/file1.properties</missing>
</file>
</activation>
...
</profile>
</profiles>
...
</settings>
有关maven配置和项目创建,下面这篇文章已经介绍的比较详细,不再赘述。
基础环境是eclipse和Maven3;
https://wenku.baidu.com/view/c40e5467c77da26924c5b0a4.html