Maven使用--setting.xml配置

配置:

打开 ${maven.home}/conf 下面的 Setting.xml ,为了大家对照方便,我只在原来的基础上更改,顺序按从上往下

配置本地 Repository

Java代码 复制代码 收藏代码
  1. <!-- localRepository
  2. | The path to the local repository maven will use to store artifacts.
  3. |
  4. | Default: ~/.m2/repository
  5. -->
  6. <localRepository>E:/LoaclRepository/m2</localRepository>
<!-- localRepository

| The path to the local repository maven will use to store artifacts.

|

| Default: ~/.m2/repository

-->
<localRepository>E:/LoaclRepository/m2</localRepository>

其中 E:/LoaclRepository/m2 是本地 Repository ,这个必须时绝对路径 。如果不改的话默认路径是在 C:\Documents and Settings \ %username%\.m2 下。其中 %username% 为操作系统登录用户名,这样不方便维护。

与用户的交互模式

Java代码 复制代码 收藏代码
  1. <!-- interactiveMode
  2. | This will determine whether maven prompts you when it needs input. If set to false,
  3. | maven will use a sensible default value, perhaps based on some other setting, for
  4. | the parameter in question.
  5. |
  6. | Default: true
  7. <interactiveMode>true</interactiveMode>
  8. -->
<!-- interactiveMode

| This will determine whether maven prompts you when it needs input. If set to false,

| maven will use a sensible default value, perhaps based on some other setting, for

| the parameter in question.

|

| Default: true

<interactiveMode>true</interactiveMode>

-->

默认为 true ,当需要输入参数时 Maven 会提示用户输入参数,如果设置为 false ,则在遇到有输入参数时不会提示用户, Maven 会自己生成一些参数,这样可能会出错,一般不需要改变默认设置。

是否连接互联网

Java代码 复制代码 收藏代码
  1. <!-- offline
  2. | Determines whether maven should attempt to connect to the network when executing a build.
  3. | This will have an effect on artifact downloads, artifact deployment, and others.
  4. |
  5. | Default: false
  6. <offline>false</offline>
  7. -->
<!-- offline

| Determines whether maven should attempt to connect to the network when executing a build.

| This will have an effect on artifact downloads, artifact deployment, and others.

|

| Default: false

<offline>false</offline>

-->

当运行的时候,决定 Maven 是否尝试与网络建立连接。这样可能会对已有的本地储藏室中的自定义 .jar 文件产生影响,默认为 false ,一般不需要改。

配置代理服务器(如果你使用代理服务器上网的话)

Java代码 复制代码 收藏代码
  1. <!-- proxies
  2. | This is a list of proxies which can be used on this machine to connect to the network.
  3. | Unless otherwise specified (by system property or command-line switch), the first proxy
  4. | specification in this list marked as active will be used.
  5. |-->
  6. <proxies>
  7. <!-- proxy
  8. | Specification for one proxy, to be used in connecting to the network.
  9. |
  10. -->
  11. <proxy>
  12. <id>optional</id><!--代理服务器ID,可随意命名-->
  13. <active>true</active><!-- 是否启用 -->
  14. <protocol>http</protocol><!-- 通信协议 -->
  15. <username>proxyuser</username><!-- 代理服务器用户名 -->
  16. <password>proxypass</password><!-- 代理服务器密码 -->
  17. <host>proxy.host.net</host><!-- 代理服务器主机地址 -->
  18. <port>80</port><!-- 通信端口 -->
  19. <nonProxyHosts></nonProxyHosts>
  20. </proxy>
  21. </proxies>
<!-- proxies
	
	| This is a list of proxies which can be used on this machine to connect to the network.
	
	| Unless otherwise specified (by system property or command-line switch), the first proxy
	
	| specification in this list marked as active will be used.
	
	|-->

<proxies>

	<!-- proxy
		
		| Specification for one proxy, to be used in connecting to the network.
		
		|
		
	-->

	<proxy>

		<id>optional</id><!--代理服务器ID,可随意命名-->

		<active>true</active><!-- 是否启用 -->

		<protocol>http</protocol><!-- 通信协议 -->

		<username>proxyuser</username><!-- 代理服务器用户名 -->

		<password>proxypass</password><!-- 代理服务器密码 -->

		<host>proxy.host.net</host><!-- 代理服务器主机地址 -->

		<port>80</port><!-- 通信端口 -->

		<nonProxyHosts></nonProxyHosts>

	</proxy>

</proxies>

其中 proxy.host.net 是你的代理服务器主机地址

展开我的项目到远程服务器

Pom .xml 文件:

Java代码 复制代码 收藏代码
  1. <distributionManagement>
  2. <repository>
  3. <id><SPAN style="BACKGROUND-COLOR: #ff0000">mycompany-repository</SPAN>
  4. </id>
  5. <name>MyCompany Repository</name>
  6. <url>scp://repository.mycompany.com/repository/maven2</url>
  7. </repository>
  8. </distributionManagement>
<distributionManagement>

	<repository>

		<id>mycompany-repository
</id>

		<name>MyCompany Repository</name>

		<url>scp://repository.mycompany.com/repository/maven2</url>

	</repository>

</distributionManagement>

Settings.xml

Java代码 复制代码 收藏代码
  1. <!-- servers
  2. | This is a list of authentication profiles, keyed by the server-id used within the system.
  3. | Authentication profiles can be used whenever maven must make a connection to a remote server.
  4. |-->
  5. <servers>
  6. <!-- server
  7. | Specifies the authentication information to use when connecting to a particular server, identified by
  8. | a unique name within the system (referred to by the 'id' attribute below).
  9. |
  10. | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
  11. | used together.
  12. |
  13. <server>
  14. <id><SPAN style="BACKGROUND-COLOR: #ff0000">deploymentRepo</SPAN>
  15. </id>
  16. <username>repouser</username>
  17. <password>repopwd</password>
  18. </server>
  19. -->
  20. <!-- Another sample, using keys to authenticate. -->
  21. <id>mycompany-repository</id>
  22. <username>jvanzyl</username>
  23. <!-- Default value is ~/.ssh/id_dsa -->
  24. <privateKey>/path/to/identity</privateKey>
  25. (default is ~/.ssh/id_dsa)
  26. <passphrase>my_key_passphrase</passphrase>
  27. </servers>
<!-- servers
	
	| This is a list of authentication profiles, keyed by the server-id used within the system.
	
	| Authentication profiles can be used whenever maven must make a connection to a remote server.
	
	|-->

<servers>

	<!-- server
		
		| Specifies the authentication information to use when connecting to a particular server, identified by
		
		| a unique name within the system (referred to by the 'id' attribute below).
		
		|
		
		| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
		
		| used together.
		
		|
		
		<server>
		
		<id>deploymentRepo

</id>
		
		<username>repouser</username>
		
		<password>repopwd</password>
		
		</server>
		
	-->



	<!-- Another sample, using keys to authenticate. -->

	<id>mycompany-repository</id>

	<username>jvanzyl</username>

	<!-- Default value is ~/.ssh/id_dsa -->

	<privateKey>/path/to/identity</privateKey>
	(default is ~/.ssh/id_dsa)

	<passphrase>my_key_passphrase</passphrase>

</servers>

注意红色代码部分;

设置多个远程镜像

Java代码 复制代码 收藏代码
  1. <mirrors>
  2. <!-- mirror
  3. | Specifies a repository mirror site to use instead of a given repository. The repository that
  4. | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
  5. | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
  6. |
  7. -->
  8. <mirror>
  9. <id>ggi-project.org</id>
  10. <url>http://ftp.ggi-project.org/pub/packages/maven2</url>
  11. <mirrorOf>central</mirrorOf>
  12. </mirror>
  13. <mirror>
  14. <id>planetmirror.com</id>
  15. <url>http://public.planetmirror.com/pub/maven2</url>
  16. <mirrorOf>central</mirrorOf>
  17. </mirror>
  18. <mirror>
  19. <id>lsu.edu</id>
  20. <url>http://ibiblio.lsu.edu/main/pub/packages/maven2</url>
  21. <mirrorOf>central</mirrorOf>
  22. </mirror>
  23. <mirror>
  24. <id>ibiblio.net</id>
  25. <url>http://www.ibiblio.net/pub/packages/maven2</url>
  26. <mirrorOf>central</mirrorOf>
  27. </mirror>
  28. </mirrors>
<mirrors>

	<!-- mirror
		
		| Specifies a repository mirror site to use instead of a given repository. The repository that
		
		| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
		
		| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
		
		|
		
	-->

	<mirror>

		<id>ggi-project.org</id>

		<url>http://ftp.ggi-project.org/pub/packages/maven2</url>

		<mirrorOf>central</mirrorOf>

	</mirror>

	<mirror>

		<id>planetmirror.com</id>

		<url>http://public.planetmirror.com/pub/maven2</url>

		<mirrorOf>central</mirrorOf>

	</mirror>

	<mirror>

		<id>lsu.edu</id>

		<url>http://ibiblio.lsu.edu/main/pub/packages/maven2</url>

		<mirrorOf>central</mirrorOf>

	</mirror>

	<mirror>

		<id>ibiblio.net</id>

		<url>http://www.ibiblio.net/pub/packages/maven2</url>

		<mirrorOf>central</mirrorOf>

	</mirror>

</mirrors>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值